Skip to content
Preptima
mediumConceptCodingScenarioMidSeniorStaff

How do goroutines leak, and how would you find a leak in a running service?

A goroutine leak in Go happens when a goroutine blocks forever on a send, receive, network call or abandoned worker path. Find it with goroutine counts and pprof, then add cancellation to every blocking operation. Use this goroutines answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects channels to the point an interviewer is testing.

5 min readUpdated 2026-08-15

Answer

Short answer

Give every goroutine a way to stop and make every blocking send, receive or I/O call observe cancellation. In production, compare goroutine profiles over time and look for stacks accumulating in the same blocked state.

Was this answer helpful?

Likely follow-ups

  • Why does buffering a channel fix some leaks but only hide others?
  • Who is responsible for closing a channel, and what happens if two producers both close it?
  • How would you write a test that fails when a function leaks a goroutine?
  • A goroutine is blocked on a network read rather than a channel. Does cancelling the context unblock it?

Related questions

Further reading

Related Topics