fix: data race in BenchmarkConnectionMainReadLoop#1040
Merged
anacrolix merged 3 commits intoanacrolix:masterfrom Feb 24, 2026
Merged
fix: data race in BenchmarkConnectionMainReadLoop#1040anacrolix merged 3 commits intoanacrolix:masterfrom
anacrolix merged 3 commits intoanacrolix:masterfrom
Conversation
Contributor
Author
|
This just *should fix your CI. you are welcome |
Contributor
Author
|
Thank Sharov Bot for this |
_pendingPieces.Add(0) was called without holding the client lock and without updating the piece request order, causing two issues: 1. Data race with timer goroutines accessing the roaring bitmap 2. Panic in checkPendingPiecesMatchesRequestOrder due to _pendingPieces and requestOrder being out of sync Replace the direct bitmap manipulation with updatePiecePriority(0, ...) which properly updates both _pendingPieces and the piece request order while holding the client lock.
19e889d to
26e9149
Compare
anacrolix
added a commit
that referenced
this pull request
Feb 24, 2026
_pendingPieces.Add(0) was called without holding the client lock and without updating the piece request order, causing two issues: 1. Data race with timer goroutines accessing the roaring bitmap 2. Panic in checkPendingPiecesMatchesRequestOrder due to _pendingPieces and requestOrder being out of sync Replace the direct bitmap manipulation with updatePiecePriority(0, ...) which properly updates both _pendingPieces and the piece request order while holding the client lock. Co-authored-by: info@weblogix.biz <admin@10gbps.weblogix.it> Co-authored-by: Matt Joiner <anacrolix@gmail.com>
anacrolix
added a commit
that referenced
this pull request
Feb 26, 2026
* fix: race condition on connIdIssued in Client.request The write to connIdIssued on error response (Connection ID mismatch) was not protected by the client mutex, racing with concurrent requestWriter goroutines that read connIdIssued via writeRequest -> connect -> shouldReconnect (which do hold the lock). Fixes erigontech/erigon#18901 * Update the golangci-lint workflow I followed the instructions at https://github.com/golangci/golangci-lint-action. * fix: data race in BenchmarkConnectionMainReadLoop (#1040) _pendingPieces.Add(0) was called without holding the client lock and without updating the piece request order, causing two issues: 1. Data race with timer goroutines accessing the roaring bitmap 2. Panic in checkPendingPiecesMatchesRequestOrder due to _pendingPieces and requestOrder being out of sync Replace the direct bitmap manipulation with updatePiecePriority(0, ...) which properly updates both _pendingPieces and the piece request order while holding the client lock. Co-authored-by: info@weblogix.biz <admin@10gbps.weblogix.it> Co-authored-by: Matt Joiner <anacrolix@gmail.com> --------- Co-authored-by: Matt Joiner <anacrolix@gmail.com> Co-authored-by: info@weblogix.biz <admin@10gbps.weblogix.it>
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.
Problem
BenchmarkConnectionMainReadLoopfails with a data race on all CI platforms (stable/ubuntu, stable/macos, oldstable/ubuntu):Cause
t._pendingPieces.Add(0)at line 123 is called without holding the client lock, racing with timer goroutines spawned by the torrent client internals that also access the roaring bitmap.Fix
Wrap
_pendingPieces.Add(0)withcl.lock()/cl.unlock()to match the locking discipline used elsewhere in the benchmark (e.g.pendAllChunkSpecsis called insidecl.lock()).