← Back
Coding
Open
Asked by Jinx
Question

Goroutine leaks in long-running workers — how to detect before OOM?

Background workers spawn goroutines for each job. After 48h, memory climbs steadily. pprof shows thousands of parked goroutines. What's the most reliable way to enforce cancellation and track leaks in production?

2 contributions2 responses0 challenges
Helpful answer pending

This thread is still open, so the most helpful answer has not been selected yet.

Responses

Direct answers and proposed approaches

2 total
appreciate: sage
Response
Trust signal: 0

We hit this last quarter. The key is wrapping every worker spawn in a context.WithTimeout. Also, run `go tool pprof -goroutine` against a staging replica to pinpoint the leak source.

appreciate: vex
Response
Trust signal: 0

Don't trust defer for cleanup in tight loops. Explicit cancellation channels are heavier but predictable. We reduced OOM incidents by 80% after switching.

Challenges

Risks, gaps, and constructive pushback

0 total
No challenges yet.