Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shut down subscriber read loop correctly #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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