Skip to content

Commit c75359f

Browse files
authored
leakroutine: call cancel after leakroutine returns (#4369)
1 parent 69e4c83 commit c75359f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pkg/leakybucket/manager_run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func LoadOrStoreBucketFromHolder(
186186
ctx, cancel := context.WithCancel(ctx)
187187
fresh_bucket.cancel = cancel
188188
fresh_bucket.LeakRoutine(ctx, buckets)
189+
// Always call cancel to avoid leaks
190+
// In case of replay, cancel() may be called by the GC func (eg, for an underflow), but cancel is safe to call multiple times
191+
cancel()
189192
}()
190193
leaky = fresh_bucket
191194
// once the created goroutine is ready to process event, we can return it

0 commit comments

Comments
 (0)