fix(monitor): implement WaitGroup synchronization and context gates to prevent shutdown panic #324#459
Conversation
…cure channel closure agnivo988#324
|
Warning Review limit reached
More reviews will be available in 9 minutes and 22 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 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 |
Contributed as part of GSSoC '26.
Problem Description
When a system shutdown or manual cancellation was triggered while background monitoring operations (
checkCommits,checkIssues, etc.) were actively making GitHub API calls, the orchestration thread would close out the primary notification pipeline channel immediately. Concurrently active worker routines finishing their network tasks would then blindly attempt to push payloads into the defunct channel, causing an unrecoverable runtime crash:panic: send on closed channel. Fixes #324.Solution Implemented
sync.WaitGroup(workerWg) to explicitly monitor the lifecycles of all four parallel analytics modules running insidecheckForUpdates.selectblock:This ensures that any routine waking up post-cancellation instantly aborts execution instead of attempting an illegal write to a closed channel.
4. Data Race Eradication: Added explicit read-write mutual exclusion locks (sync.RWMutex) across all background evaluation routines and data persistence hooks (saveState) to guarantee complete memory visibility safety during parallel sweeps.
5. Simulated Panic Regression Test: Authored a specialized verification harness simulating high-concurrency event drops during rapid shutdown cycles. The test confirms clean, zero-fault exits across all parallel tracks.
Verification & Test Logs
Verified successfully on the local testbed setup:
go test -v ./internal/monitor/...: PASSED (All graceful shutdown edge cases fully validated)
go build ./...: PASSED (Clean binary compilation metrics)