goroutine leak
A goroutine that never finishes because it is stuck waiting for something that will never happen, slowly wasting memory.
Leaked goroutines accumulate until the service exhausts memory and is killed.
In more detail
Typical causes are sending on a channel nobody reads, or waiting on a network call with no timeout. In a long-running service leaks pile up until the process runs out of memory. Give every goroutine a way to stop, usually a context, and join it before exit.
Related terms
- goroutine — A function running concurrently with the rest of a Go program, started by putting the go keyword before a call.
- context cancellation — Telling every function using a context to stop, by calling the cancel function returned when the context was created.
- blocking operation — An operation that makes the code wait until something happens, such as a receive waiting for a value to arrive on a channel.
- sync.WaitGroup — A counter from Go's sync package that lets one goroutine wait until a group of other goroutines have all finished.
Taught in
- Context Cancellation and Timeouts — Concurrent Systems Programming with Go