fix ticker mix up (#1807)
Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
This commit is contained in:
parent
4b3c9c2806
commit
7359586f1c
|
@ -196,7 +196,7 @@ func LeakRoutine(leaky *Leaky) error {
|
|||
|
||||
var (
|
||||
durationTicker <-chan time.Time = make(<-chan time.Time)
|
||||
underflowTicker *time.Ticker
|
||||
firstEvent bool = true
|
||||
)
|
||||
|
||||
defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name))
|
||||
|
@ -240,12 +240,19 @@ func LeakRoutine(leaky *Leaky) error {
|
|||
|
||||
leaky.Pour(leaky, *msg) // glue for now
|
||||
//Clear cache on behalf of pour
|
||||
if underflowTicker != nil {
|
||||
underflowTicker.Stop()
|
||||
|
||||
// if durationTicker isn't initialized, then we're pouring our first event
|
||||
if firstEvent {
|
||||
durationTicker = time.NewTicker(leaky.Duration).C
|
||||
}
|
||||
underflowTicker = time.NewTicker(leaky.Duration)
|
||||
durationTicker = underflowTicker.C
|
||||
defer underflowTicker.Stop()
|
||||
|
||||
// reinitialize the durationTicker when it's not a counter bucket
|
||||
if !leaky.timedOverflow {
|
||||
ticker := time.NewTicker(leaky.Duration)
|
||||
durationTicker = ticker.C
|
||||
defer ticker.Stop()
|
||||
}
|
||||
firstEvent = false
|
||||
/*we overflowed*/
|
||||
case ofw := <-leaky.Out:
|
||||
leaky.overflow(ofw)
|
||||
|
|
Loading…
Reference in a new issue