Skip to content

Conversation

nickstenning
Copy link

readLoop was leaking goroutines when subscribers were unsubscribed, because it was blocked trying to write a nil to erChan in response to an upstream io.EOF.

This commit passes in a context to startReadLoop, ensuring that when that context is closed, the read loop terminates correctly.

For SubscribeWithContext we just pass in the parent context, as there is no way to unsubscribe the handler.

For SubscribeChanWithContext, we pass in a derived cancelable context, which we cancel explicitly when the channel is unsubscribed.

For the maintainers: I'm not sure if this is the right fix for the underlying problem here. Very happy to go back and forth with you on what the correct fix actually is, and get this patch in shape.

readLoop was leaking goroutines when subscribers were unsubscribed,
because it was blocked trying to write a nil to erChan in response to an
upstream io.EOF.

This commit passes in a context to startReadLoop, ensuring that when
that context is closed, the read loop terminates correctly.

For SubscribeWithContext we just pass in the parent context, as there is
no way to unsubscribe the handler.

For SubscribeChanWithContext, we pass in a derived cancelable context,
which we cancel explicitly when the channel is unsubscribed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant