Skip to content

Commit 532b01f

Browse files
[release-1.22] Fix goroutine/memory leak in SubjectAndFiltersPass (#9152)
Fix goroutine/memory leak in SubjectAndFiltersPass SubjectAndFiltersPass created filter objects via CreateSubscriptionsAPIFilters on every request but never called Cleanup() on them. The anyFilter and allFilter types each spawn a background goroutine (optimizeLoop) that only terminates when Cleanup() is called, causing goroutines, channels, and filter objects to leak on every event dispatch. Under sustained error traffic (e.g. dispatching to non-existing sinks), this accumulated millions of leaked goroutines and eventually caused the imc-dispatcher to OOM crash. Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
1 parent 9c09ed6 commit 532b01f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

pkg/auth/event_policy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ func SubjectAndFiltersPass(ctx context.Context, sub string, allowedSubsWithFilte
227227
for _, swf := range allowedSubsWithFilters {
228228
for _, s := range swf.Subjects {
229229
if strings.EqualFold(s, sub) || (strings.HasSuffix(s, "*") && strings.HasPrefix(sub, strings.TrimSuffix(s, "*"))) {
230-
return subscriptionsapi.CreateSubscriptionsAPIFilters(logger.Desugar(), swf.Filters).Filter(ctx, *event) != eventfilter.FailFilter
230+
filter := subscriptionsapi.CreateSubscriptionsAPIFilters(logger.Desugar(), swf.Filters)
231+
defer filter.Cleanup()
232+
return filter.Filter(ctx, *event) != eventfilter.FailFilter
231233
}
232234
}
233235
}

0 commit comments

Comments
 (0)