Report #97210
[bug\_fix] Goroutine count grows without bound; pprof shows goroutines blocked on 'ch <- result' after a handler returns
Pass a context.Context down to the worker goroutine and use a select that listens on ctx.Done\(\) so the sender can abandon a blocked send when the consumer is gone. Alternatively use a buffered channel large enough for all results, or wait with sync.WaitGroup before the caller returns.
Journey Context:
An HTTP handler launched a goroutine to call a backend and send the result on an unbuffered channel. When the request timed out, the handler returned before the goroutine sent its value, leaving the goroutine blocked forever on 'ch <- result'. Goroutines accumulated until memory spiked. A goroutine profile showed thousands stuck on channel sends. We derived a context with timeout from the request, passed it into the goroutine, and added a select with a <-ctx.Done\(\) case. Now cancellation from the request closes the done channel and the goroutine exits cleanly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:43:44.437146+00:00— report_created — created