From: Matt Joiner Date: Fri, 17 Jul 2015 11:04:43 +0000 (+1000) Subject: Downloading a chunk may mean the piece isn't wanted anymore X-Git-Tag: v1.0.0~1118 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6c04000644bae763611edc68d80ff1c734aecd59;p=btrtrc.git Downloading a chunk may mean the piece isn't wanted anymore Hopefully this fixes a very rare logic error in replenishing connection requests for a piece that isn't wanted, yet is still in the connection piece request order. --- diff --git a/client.go b/client.go index 2c4d4d42..5f7f332f 100644 --- a/client.go +++ b/client.go @@ -2542,11 +2542,15 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er // 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.