client.go | 6 +++++- diff --git a/client.go b/client.go index 2c4d4d42c8689d59233e80cc97bc765824d5830b..5f7f332f82ab9b099022539a4681796caf6a3a36 100644 --- a/client.go +++ b/client.go @@ -2542,11 +2542,15 @@ piece.Event.Broadcast() // Record that we have the chunk. piece.unpendChunkIndex(chunkIndex(req.chunkSpec, t.chunkSize)) delete(t.urgent, req) + // It's important that the piece is potentially queued before we check if + // the piece is still wanted, because if it is queued, it won't be wanted. if piece.numPendingChunks() == 0 { + me.queuePieceCheck(t, req.Index) + } + if !t.wantPiece(int(req.Index)) { for _, c := range t.Conns { c.pieceRequestOrder.DeletePiece(int(req.Index)) } - me.queuePieceCheck(t, req.Index) } // Cancel pending requests for this chunk.