Skip to content

Commit fab369a

Browse files
Giulio2002info@weblogix.bizanacrolix
authored
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>
1 parent c3b35bb commit fab369a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

peerconn_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func BenchmarkConnectionMainReadLoop(b *testing.B) {
120120
}))
121121
//t.storage = &storage.Torrent{TorrentImpl: storage.TorrentImpl{Piece: ts.Piece, Close: ts.Close}}
122122
//t.onSetInfo()
123+
cl.lock()
124+
t.updatePiecePriority(0, "benchmark setup")
125+
cl.unlock()
123126
r, w := net.Pipe()
124127
b.Logf("pipe reader remote addr: %v", r.RemoteAddr())
125128
cn := cl.newConnection(r, newConnectionOpts{

0 commit comments

Comments
 (0)