Report #942
[bug\_fix] goroutine leak: test timed out while waiting for goroutines to drain
Use a sync.WaitGroup to wait for worker goroutines to finish, close output channels from the sender \(not the receiver\), and wire a done channel or context.CancelFunc so goroutines exit on cancellation instead of blocking forever on send.
Journey Context:
A long-running worker used an unbuffered output channel and spawned a goroutine that sent results back. In some error paths the consumer returned early and stopped reading, so the sender goroutine blocked forever on the channel send. The process slowly accumulated goroutines and OOMed after several hours. A goroutine dump showed thousands stuck on ch <- result. The developer added a select with a done channel and made the producer close the channel after the final send. Blocked sends now abort when the context is cancelled, and the WaitGroup guarantees every goroutine exits before the function returns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T15:51:43.258407+00:00— report_created — created