Fix deadlock on duplicate PooledTransactions response - #151
Open
damilolaedwards wants to merge 1 commit into
Open
Fix deadlock on duplicate PooledTransactions response#151damilolaedwards wants to merge 1 commit into
damilolaedwards wants to merge 1 commit into
Conversation
handlePooledTransactions sent to the per-request channel while holding pooledTransactionsMux. A peer that replied twice to the same request ID could make the second send block forever on an unbuffered, already drained channel, while still holding the mutex. That wedged the whole session read loop, and the original caller's deferred cleanup then blocked forever trying to acquire the same lock. Make the channel buffered so the first reply never has to wait for the receiver to be ready, and make the send non-blocking so any extra reply for a request that has already been answered is dropped instead of stalling the read loop. Adds a test that replays a duplicate response over a real handshake and confirms the mutex is still available afterward. Confirmed the test fails against the previous behavior and passes with the fix.
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.
Summary
handlePooledTransactions sent to the per-request channel while holding pooledTransactionsMux. A peer that replied twice to the same request ID could make the second send block forever on an unbuffered, already drained channel, while still holding the mutex. That wedged the whole session read loop, and the original caller's deferred cleanup then blocked forever trying to acquire the same lock.
Makes the channel buffered so the first reply never has to wait for the receiver to be ready, and makes the send non-blocking so any extra reply for a request that has already been answered is dropped instead of stalling the read loop. The map lookup and the send still happen under the same lock as before, so there is no window where a stale or closed channel could be sent to.
Test plan
go build ./...,go vet ./..., and the full package test suite all pass.