attempt to fix ticker leak (#1620)
This commit is contained in:
parent
02e0f3c095
commit
ca4cd6d559
|
@ -195,7 +195,8 @@ 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)
|
durationTicker <-chan time.Time = make(<-chan time.Time)
|
||||||
|
underflowTicker *time.Ticker
|
||||||
)
|
)
|
||||||
|
|
||||||
defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name))
|
defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name))
|
||||||
|
@ -239,9 +240,12 @@ func LeakRoutine(leaky *Leaky) error {
|
||||||
|
|
||||||
leaky.Pour(leaky, *msg) // glue for now
|
leaky.Pour(leaky, *msg) // glue for now
|
||||||
//Clear cache on behalf of pour
|
//Clear cache on behalf of pour
|
||||||
tmp := time.NewTicker(leaky.Duration)
|
if underflowTicker != nil {
|
||||||
durationTicker = tmp.C
|
underflowTicker.Stop()
|
||||||
defer tmp.Stop()
|
}
|
||||||
|
underflowTicker = time.NewTicker(leaky.Duration)
|
||||||
|
durationTicker = underflowTicker.C
|
||||||
|
defer underflowTicker.Stop()
|
||||||
/*we overflowed*/
|
/*we overflowed*/
|
||||||
case ofw := <-leaky.Out:
|
case ofw := <-leaky.Out:
|
||||||
leaky.overflow(ofw)
|
leaky.overflow(ofw)
|
||||||
|
|
Loading…
Reference in a new issue