Skip to content

txpool/legacypool: fix fillPool TOCTOU and remove debug prints#2269

Open
lucca30 wants to merge 1 commit into
developfrom
fix/legacypool-fillpool-flake
Open

txpool/legacypool: fix fillPool TOCTOU and remove debug prints#2269
lucca30 wants to merge 1 commit into
developfrom
fix/legacypool-fillpool-flake

Conversation

@lucca30

@lucca30 lucca30 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Flaky test fix: fillPool in legacypool2_test.go read pool.Stats() and pool.all.Slots() in two separate critical sections (pool.mu.RLock and t.lock.RLock). A concurrent pool mutation between the two reads could produce an inconsistent snapshot, causing TestLockOrdering_ReplacePendingNoDeadlock to fail with have 199, want 200.
  • Fix: hold pool.mu.RLock across both reads in fillPool, using the unexported pool.stats() (valid since the test is in the same package). All paths that mutate pool.all require pool.mu.Lock, so the two reads are now atomic with respect to pool mutations.
  • Debug print removal: three leftover fmt.Println calls in list_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 expected
  • go test ./core/txpool/legacypool/... -count=1 — full package passes

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.
@sonarqubecloud

Copy link
Copy Markdown

@lucca30 lucca30 marked this pull request as ready for review June 10, 2026 18:16

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.39%. Comparing base (cb7ffc4) to head (51a0144).

Additional details and impacted files

Impacted file tree graph

@@             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
see 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant