Pipeline example in Golang Blog and possible resouce leak

I was studying the following blog post on Go’s concurrency patterns: https://blog.golang.org/pipelines

Under the section “Explicit cancellation”, main goroutine broadcasts its denial to receive any more data but it broadcasts, seemingly, to “merge” and “sq” upstream goroutines only (not to “gen” goroutine).

In this situation, since “sq” stage would not be attempting to accept data from inbound channels from “gen”, I think it is probable to have resource leak since “gen” would be blocked indefinitely.

Is my understanding correct or am I missing something. Please explain.

Just looking quickly at the blog post, gen was rewritten in the section prior to “Explicit cancellation” to use a len(input)-buffered channel and not be a goroutine at all. Probably the intention is that that implementation is kept in the next section.

1 Like

So basically, this gen (with buffered channel) implementation does not care if the receiver has abandoned the inbound channel from gen! Thanks for the answer, it did clear me my question!! Thanks again.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.