shutdown: manage connections before shutting down executors #501
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous implementation of shutdown relied on the shutdown of the top-level worker group causing the bound channel to not be able to execute any events, which effectively prevented the bound channel from receiving any more connections. It didn't actually close the channel
This had a side effect of causing existing connections to crash noisily as one or more handlers in the pipeline relied on the top-level executor group and submitted work to a closed executor. I believe it also had a side-effect of crashing the bound channel, which is how it stops listening.
By closing the connections first (in a reasonable order, server first), we can ensure that the connections are closed and that their channel pipelines will not submit work to executors that will reject them.
This change applies the guidance from netty docs "Simplify shutdown process with ChannelGroup".
Perhaps worth noting, the
Server
here has non-threadsafe code inServer#listen
to support reuse of the plugin shutdown if it is already running. I don't believe that this code is accessible, nor that it would reliably work reliably due to the lack of threadsafety, but have not made pairwise changes to that unusual shutdown sequence.