Repository navigation
fix(rulemanager): scope monitorContainer exit to its own registration - #920
Merged
matthyx merged 1 commit intoAug 24, 2026
Merged
Conversation
monitorContainer re-derived liveness by polling rm.trackedContainers on a 5s ticker instead of listening for its own registration's removal. A container removed and re-added faster than one tick left the stale goroutine's poll seeing the ID "tracked again" (from the new Add), so it never exited while ContainerCallback spawned a second monitorContainer for the same ID -- leaking one goroutine per such cycle. Each ContainerCallback Add now creates a done channel scoped to that registration and passes it directly into monitorContainer, which blocks on it instead of polling shared state. Remove closes and clears the current registration's channel, so only the removal that owns a given goroutine can stop it -- a re-Add's fresh channel has no effect on the old one. Fixes #919 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HS36ZHmKzkzibNi1oHVNUQ Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx
force-pushed
the
fix/rulemanager-monitor-container-goroutine-leak-919
branch
from
August 24, 2026 10:41
e7d9fd2 to
6ab4261
Compare
|
Warning Review limit reachedNext included review available in 57 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Performance Benchmark ResultsNode-Agent Resource Usage
Dedup EffectivenessNo data available. |
matthyx
deleted the
fix/rulemanager-monitor-container-goroutine-leak-919
branch
August 24, 2026 11:43
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RuleManager.monitorContainerleaked one goroutine per container remove→add cycle that happened faster than its 5s polling ticker, because it re-derived its own liveness from shared mutable state instead of a registration-scoped signal. This gives each registration its owndonechannel so a goroutine can only be stopped by the removal that owns it.Overview
RuleManager.monitorContainerused to re-derive its own liveness by pollingrm.trackedContainers.Contains(k8sContainerID)on a 5s ticker instead of watching for its own registration's removal. If a container was removed and re-added faster than one tick, the stale goroutine's poll saw the ID "tracked again" (from the new Add) and looped forever, whileContainerCallbackspawned a brand-newmonitorContainergoroutine for the same ID — leaking one goroutine per such remove→add cycle, permanently, for the life of the process.This gives each
ContainerCallbackEventTypeAddContainerits own scopeddone chan struct{}, stored in a newRuleManager.trackedContainerDonemap and passed directly intostartRuleManager/monitorContaineras a parameter.monitorContainernow blocks on that channel (orrm.ctx.Done()) instead of polling shared state, andEventTypeRemoveContainercloses + clears the current registration's channel. Because the goroutine holds its channel via closure rather than re-reading a shared ID-keyed map at wake time, only the removal that owns a given registration can stop it — a sibling/later registration's channel has no effect on it. This closes the race structurally rather than narrowing the polling window, and also makes container-removal shutdown immediate instead of waiting up to 5s.The now-unused
syscallPeriodticker and itscontainer.Mntns == 0debug check were removed along with the polling loop.Additional Information
Added
docs/features/rulemanager-monitor-container-lifecycle.mddocumenting the bug, the fix, and the observable behavior change.How to Test
New tests in
pkg/rulemanager/containercallbacks_test.go:TestMonitorContainer_ExitsOnDoneChannel— exits when its own channel closes.TestMonitorContainer_IgnoresSiblingDoneChannel— does not exit when an unrelated channel closes.TestContainerCallback_FastRemoveAddDoesNotLeakGoroutine— reproduces the Add→Remove→Add race end-to-end throughContainerCallbackand asserts the stale registration's channel is closed while the current registration's channel stays open and is a distinct channel.Related issues/PRs:
AI-skills: none | cmds: /oh-my-claudecode:autopilot