The Suspense example uses goroutines which will finish when the channel is read. If the channel is never read (or only partially read) then goroutines will never finish. A buffered channel should be used so that the goroutines can finish without requiring the channel to be consumed. Although the example itself is OK, since it's referenced by the docs it should be able to be copy/pasted without errors potentially being introduced.
A similar pattern is described in the official Go blog article Go Concurrency Patterns: Pipelines and cancellation and it warns:
goroutines consume memory and runtime resources, and heap references in goroutine stacks keep data from being garbage collected. Goroutines are not garbage collected; they must exit on their own.
The alternative strategy is to use a done channel which would be closed by the http handler function.
The Suspense example uses goroutines which will finish when the channel is read. If the channel is never read (or only partially read) then goroutines will never finish. A buffered channel should be used so that the goroutines can finish without requiring the channel to be consumed. Although the example itself is OK, since it's referenced by the docs it should be able to be copy/pasted without errors potentially being introduced.
A similar pattern is described in the official Go blog article Go Concurrency Patterns: Pipelines and cancellation and it warns:
The alternative strategy is to use a
donechannel which would be closed by the http handler function.