Repository navigation
leakybucket: unstrand bucket goroutines parked on their final send after reload - #4755
choksi2212 wants to merge 1 commit into
Conversation
…ter reload Every bucket live at a SIGHUP reload is stranded forever: LeakRoutine's final event send blocks on the shared buffer-1 overflow channel whose only readers (the output loops) were already stopped by ShutdownCrowdsecRoutines. One orphaned cleanup event fills the buffer and wedges every other bucket. Shutdown now closes a per-generation channel that the four send sites select on, so the parked sends drop their event and the goroutines exit. While readers are alive, sends keep the exact plain-send semantics, so backpressure and the GC cleanup markers are unchanged. Fixes crowdsecurity#4748 Signed-off-by: choksi2212 <choksi2212@users.noreply.github.com>
|
@choksi2212: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
|
@choksi2212: There are no area labels on this PR. You can add as many areas as you see fit.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
|
/kind fix |
|
/area agent |
|
Still green after two weeks — happy to rework anything if the approach needs it, or rebase if that makes review easier. The bucket-strand case it fixes is easy to reproduce from the issue, and the regression tests pin both the stranded-send and the reload ordering. |
|
I can confirm that this issue is affecting a production environment running CrowdSec v1.7.7 on Ubuntu 24.04. We captured the goroutine profile directly from the production agent: goroutine profile: total 47153 40256 goroutines at: 6741 goroutines at: The stack traces point directly to Leaky.LeakRoutine, matching the problem addressed by this PR. The issue was observed after repeated SIGHUP reloads, including reloads triggered automatically by crowdsec-hubupdate.service. This PR addresses a real production problem. We are looking forward to testing the fix once it becomes available in an official release. Thank you for working on this! |
What and why
Every bucket live at a SIGHUP reload is stranded forever, as reported in #4748:
LeakRoutine's final event send blocks on the shared buffer-1AllOutchannel whose only readers (the output loops) were already stopped byShutdownCrowdsecRoutines. One orphaned cleanup event fills the buffer and wedges every other bucket.All four
AllOutsend sites now select on a per-generationretDonechannel that shutdown closes once the readers are provably dead (after the 3soutputsTomb.Wait, beforecancel()). A parked send then drops its event and the goroutine exits. While the readers are alive,retDoneis not closed and the send keeps the exact plain-send semantics, so backpressure, the overflow path and the GC cleanup markers are unchanged. Buckets built without a factory (tests) get a nil channel, which is the plain send.One concern only: this does not touch the pour busy-wait of #4734, nor the errgroup membership of bucket goroutines.
Fixes #4748
How it was tested
TestLeakRoutineExitsWhenOutputReadersAreGoneruns two live buckets sharing the buffer-1 channel, stops the readers, closesretDone, then cancels the context. On master the second bucket parks forever (the test times out with "LeakRoutine is still parked on its final send after shutdown", which is the issue at unit scale); with this change both goroutines exit.TestLeakRoutineStillDeliversWhileReadersLivepins the other side: with a live reader, a canceled bucket still delivers its cleanup event, so GC'd buckets can't silently vanish.go test -race ./pkg/leakybucket/fails on my Windows box, with the same three race families (exprhelpers debugger, namegenerator math/rand, uniq cache init) on master and on this branch; the uniq one reproduces on master with-run TestBucket/simple-leaky-uniq -count=5. None of the stacks touch the changed lines.Checklist
cscli -o json|rawoutput.AI assistance used: mostly