This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
Fix potential stall in world state download #922
Merged
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.
PR description
There's an issue with the world state downloader where the download process could stall. The sequence goes like:
requestDataFromPeer
thread A takes out thesendingRequests
lockshouldRequestNodeData
which returnstrue
shouldRequestNodeData
which returnsfalse
so it exits the while loopshouldRequestNodeData
but fails to get thesendingRequests
lock so exits the methodsendingRequests
lock and exits the methodsThere are now no threads checking if they should send new requests and no outstanding requests to trigger a check in the future so the download is stuck and will never make anymore progress.
The fix is to switch the order of taking out the
sendingRequests
lock and checkingshouldRequestNodeData
so we release thesendingRequests
lock before we go back round the loop to checkshouldRequestNodeData
.To make the interactions of locks and this loop clearer I've extract a couple of methods so the
requestNodeData
method is shorter and focussed just on the locking and looping behaviour.