Skip to content

Commit

Permalink
fix dirty chunk missing lock (debug)
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed May 31, 2024
1 parent c2e76bf commit bf2490a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {

ppReq := newRequestFromMessage(msg)
t := c.t
// ok to here
err := t.checkValidReceiveChunk(ppReq)
if err != nil {
err = log.WithLevel(log.Warning, err)
Expand Down
8 changes: 8 additions & 0 deletions requesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func (p *Peer) getDesiredRequestStateDebug() (desired desiredRequestState) {

// Caller-provided allocation for roaring bitmap iteration.
var it typedRoaring.Iterator[RequestIndex]

t.mu.RLock()
var dirtyChunks = t.dirtyChunks.Clone()
t.mu.RUnlock()

requestStrategy.GetRequestablePieces(
input,
t.getPieceRequestOrder(),
Expand All @@ -270,6 +275,9 @@ func (p *Peer) getDesiredRequestStateDebug() (desired desiredRequestState) {
}
requestHeap.pieceStates[pieceIndex] = pieceExtra
allowedFast := p.peerAllowedFast.Contains(pieceIndex)

it.Initialize(&dirtyChunks)

t.iterUndirtiedRequestIndexesInPiece(&it, pieceIndex, func(r requestStrategy.RequestIndex) {
iterCount++
if !allowedFast {
Expand Down
2 changes: 2 additions & 0 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ func (t *Torrent) writePeerStatuses(w io.Writer, peers []*Peer) {
}

func (t *Torrent) haveInfo() bool {
t.mu.RLock()
defer t.mu.RUnlock()
return t.info != nil
}

Expand Down

0 comments on commit bf2490a

Please sign in to comment.