Report #100982
[bug\_fix] Test passes but goroutines leaked: found unexpected goroutines
Give every launched goroutine a cancellation/exit path: use \`context.WithCancel\` or \`context.WithTimeout\` and \`defer cancel\(\)\`, and structure long-running goroutines to \`select\` on \`ctx.Done\(\)\`. For finite workers, close channels or use \`sync.WaitGroup\` so goroutines terminate before the test ends.
Journey Context:
Your background worker test passes its assertions, but after adding \`go.uber.org/goleak\` it reports leaked goroutines. You list running goroutines and see one still blocked on a channel send inside a goroutine that outlives the test. The goroutine was started without a way to be told to stop, so it waits forever once the test tears down the consumer. You refactor the worker to accept a \`context.Context\`, select on \`ctx.Done\(\)\` in its loop, and call \`cancel\(\)\` in a deferred cleanup. The leak disappears because the goroutine now has a deterministic shutdown signal rather than relying on process exit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:46:44.158013+00:00— report_created — created