fix ticker (#1858)
Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
This commit is contained in:
parent
668627f890
commit
8aca00326d
|
@ -195,8 +195,9 @@ func FromFactory(bucketFactory BucketFactory) *Leaky {
|
||||||
func LeakRoutine(leaky *Leaky) error {
|
func LeakRoutine(leaky *Leaky) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
durationTicker <-chan time.Time = make(<-chan time.Time)
|
durationTickerChan <-chan time.Time = make(<-chan time.Time)
|
||||||
firstEvent bool = true
|
durationTicker *time.Ticker
|
||||||
|
firstEvent bool = true
|
||||||
)
|
)
|
||||||
|
|
||||||
defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name))
|
defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name))
|
||||||
|
@ -242,15 +243,16 @@ func LeakRoutine(leaky *Leaky) error {
|
||||||
//Clear cache on behalf of pour
|
//Clear cache on behalf of pour
|
||||||
|
|
||||||
// if durationTicker isn't initialized, then we're pouring our first event
|
// if durationTicker isn't initialized, then we're pouring our first event
|
||||||
if firstEvent {
|
|
||||||
durationTicker = time.NewTicker(leaky.Duration).C
|
|
||||||
}
|
|
||||||
|
|
||||||
// reinitialize the durationTicker when it's not a counter bucket
|
// reinitialize the durationTicker when it's not a counter bucket
|
||||||
if !leaky.timedOverflow {
|
if !leaky.timedOverflow || firstEvent {
|
||||||
ticker := time.NewTicker(leaky.Duration)
|
if firstEvent {
|
||||||
durationTicker = ticker.C
|
durationTicker = time.NewTicker(leaky.Duration)
|
||||||
defer ticker.Stop()
|
durationTickerChan = durationTicker.C
|
||||||
|
defer durationTicker.Stop()
|
||||||
|
} else {
|
||||||
|
durationTicker.Reset(leaky.Duration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
firstEvent = false
|
firstEvent = false
|
||||||
/*we overflowed*/
|
/*we overflowed*/
|
||||||
|
@ -266,7 +268,7 @@ func LeakRoutine(leaky *Leaky) error {
|
||||||
leaky.logger.Tracef("Returning from leaky routine.")
|
leaky.logger.Tracef("Returning from leaky routine.")
|
||||||
return nil
|
return nil
|
||||||
/*we underflow or reach bucket deadline (timers)*/
|
/*we underflow or reach bucket deadline (timers)*/
|
||||||
case <-durationTicker:
|
case <-durationTickerChan:
|
||||||
var (
|
var (
|
||||||
alert types.RuntimeAlert
|
alert types.RuntimeAlert
|
||||||
err error
|
err error
|
||||||
|
|
Loading…
Reference in a new issue