p2p: read dial scheduler bookkeeping under the lock - #1026
Open
hyunsooda wants to merge 1 commit into
Open
Conversation
getCandidates releases ds.mu after copying the static nodes, then keeps reading connectedAll, static, connectedOutbound and dialing. Those sets have no internal synchronisation and are written from the handshake, peer and dial goroutines, so the reads race with ordinary peer churn. The logging reads happen at any log level, because the arguments are evaluated before the call. Take the four counts while the lock is still held and use the local values afterwards. The lock cannot simply be extended over the rest of the function: the dynamic candidate path acquires it again, and sync.RWMutex is not reentrant. Constraint: the lock must be released before the dynamic candidate lookup Rejected: hold ds.mu for the whole function | dynamicCandidateAllowed re-acquires it, which deadlocks once a writer is queued Rejected: give typedNodeSet its own mutex | doubles the locking and breaks reading several sets as one consistent snapshot Confidence: high Scope-risk: narrow Not-tested: no dedicated regression test; TestServerDial catches a reintroduction under -race in roughly half of its runs Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Proposed changes
Problem
getCandidatesreleasesds.muafter copying the static nodes, then keeps readingconnectedAll,static,connectedOutboundanddialing, which are written from the handshake, peer and dial goroutines.Fix
Types of changes
Checklist
I have read the CLA Document and I hereby sign the CLAin first time contribute after having read CLA$ make test)Related issues
Further comments