Skip to content

p2p/discover: hold table mutex in tests that read buckets directly - #1692

Merged
libotony merged 2 commits into
masterfrom
tony/discover-table-test-race
Oct 26, 2026
Merged

libotony merged 2 commits into
masterfrom
tony/discover-table-test-race

Conversation

@libotony

Copy link
Copy Markdown
Member

TestTable_closest calls tab.closest(), tab.len() and walks tab.buckets without holding tab.mutex, while the table's background revalidation goroutine may bump() entries under the lock at any time. closest documents that the caller must hold the mutex; every production caller does. With 5000 tables per run the race detector hits it occasionally, failing the test_race job (e.g. run 36824221890).

Hold the mutex for the read-only checks after stuff(). TestTable_ReadRandomNodesGetAll has the same unguarded len() read; take the lock around that read only, since ReadRandomNodes locks internally.

Test-only change. Before: go test -race -count=10 -run TestTable_closest ./p2p/discover failed 1/10 locally; after: 0/30.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@libotony
libotony marked this pull request as ready for review October 22, 2026 10:47
@libotony
libotony requested a review from a team as a code owner October 22, 2026 10:47
@libotony
libotony merged commit 7ea832b into master Oct 26, 2026
66 of 67 checks passed
@libotony
libotony deleted the tony/discover-table-test-race branch October 26, 2026 04:02
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.

3 participants