fix(backup): avoid hang when closing unbound channel - #18
Open
vividctrlalt wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
BackupServer.close()can hang if it racesstart()'s bind, and the keep-alive task canwrite()after the UDP channel is already closed (logger.error("Exception in send keep alive")).Why
channelwas a plain field next to avolatile boolean shutdown. Those two writes form a Dekker pair:close()must observe a completed bind, andstart()must observeshutdownafter publishingchannel. Withoutvolatileonchannel,close()can see a still-null channel, skipchannel.close(), and leavecloseFuture().sync()blocked.The keep-alive scheduler is a second window. If the channel is closed while the scheduled task is still eligible to run,
MessageHandler.accept()writes to a closed channel.BackupManager.stop()waits for the executor and cannot be used for that first step.Changes
BackupServer.channelvolatile(Dekker withshutdown).start(), ifshutdownis already set, close the channel immediately.close()order: stop the keep-alive scheduler without waiting (BackupManager.stopScheduler()—shutdown()only), close the channel, thenbackupManager.stop().BackupServerTestpollsisBound()instead ofThread.sleep(1000).chooseRandomPort/checkPortAvailablealso probe UDP.setReuseAddressafter bind is removed (the socket is already bound; the call does not affect the bind that just succeeded and can report a port as free when it is not).Test plan
./gradlew :framework:test --tests org.tron.common.backup.BackupServerTest