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

pool: Avoid potential send to closed chan in hub. #397

Merged

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 27, 2023

This avoids a potential case in the hub that could result in a panic during shutdown due to sending to a closed channel.

Since the rpcclient callbacks can be invoked at any, even after the context is done, some additional synchronization would be required to prevent attempting to send to the closed channels if they are closed when the context is done.

Rather than adding more elaborate synchronization logic, this simply chooses not to close the channels to resolve the situation because there really isn't any reason to close them and not closing them also resolves a secondary issue. Namely, the receiving side doesn't check if the channels are closed, so closing them could actually lead to the channel being incorrectly selected without an accompanying message which itself could lead to a panic.

Finally, the receiving goroutine will be exited when the context completes meaning there won't be anything listening to the channels in very short order either which is even more reason not to worry about closing them.

This avoids a potential case in the hub that could result in a panic
during shutdown due to sending to a nil channel.

Since the rpcclient callbacks can be invoked at any, even after the
context is done, some additional synchronization would be required to
prevent attempting to send to the closed channels if they are closed
when the context is done.

Rather than adding more elaborate synchronization logic, this simply
chooses not to close the channels to resolve the situation because there
really isn't any reason to close them and not closing them also resolves
a secondary issue.  Namely, the receiving side doesn't check if the
channels are closed, so closing them could actually lead to the channel
being incorrectly selected without an accompanying message which itself
could lead to a panic.

Finally, the receiving goroutine will be exited when the context
completes meaning there won't be anything listening to the channels in
very short order either which is even more reason not to worry about
closing them.
@jholdstock jholdstock merged commit 3d37801 into decred:master Sep 27, 2023
2 checks passed
@davecgh davecgh deleted the hub_avoid_potential_send_to_closed_chan branch September 27, 2023 08:16
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.

2 participants