txpool/legacypool: fix fillPool TOCTOU and remove debug prints#2269
Open
lucca30 wants to merge 1 commit into
Open
txpool/legacypool: fix fillPool TOCTOU and remove debug prints#2269lucca30 wants to merge 1 commit into
lucca30 wants to merge 1 commit into
Conversation
fillPool read pool.Stats() (pool.mu.RLock) and pool.all.Slots() (t.lock.RLock) as two separate critical sections, creating a narrow window where a concurrent pool mutation could make pending != slots even with a healthy pool. Hold pool.mu.RLock across both reads so the snapshot is consistent; all paths that modify pool.all require pool.mu.Lock, so this is sufficient. Also removes three leftover fmt.Println debug statements from list_test.go that polluted CI output.
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2269 +/- ##
===========================================
- Coverage 53.39% 53.39% -0.01%
===========================================
Files 896 896
Lines 159713 159713
===========================================
- Hits 85278 85272 -6
- Misses 69100 69112 +12
+ Partials 5335 5329 -6 see 28 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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
fillPoolinlegacypool2_test.goreadpool.Stats()andpool.all.Slots()in two separate critical sections (pool.mu.RLockandt.lock.RLock). A concurrent pool mutation between the two reads could produce an inconsistent snapshot, causingTestLockOrdering_ReplacePendingNoDeadlockto fail withhave 199, want 200.pool.mu.RLockacross both reads infillPool, using the unexportedpool.stats()(valid since the test is in the same package). All paths that mutatepool.allrequirepool.mu.Lock, so the two reads are now atomic with respect to pool mutations.fmt.Printlncalls inlist_test.go(TestFilterTxConditionalKnownAccounts) polluted CI output; replaced with blank identifier assignments and removed the unused"fmt"import.Test plan
go test ./core/txpool/legacypool/... -count=50 -run TestLockOrdering_ReplacePendingNoDeadlock— no failures expectedgo test ./core/txpool/legacypool/... -count=1— full package passes