reader.go | 10 ++++++++++ diff --git a/reader.go b/reader.go index a6a5bc616c196478a3014901b76e07eb5600b36e..8610910d772606ebbc172a99ec7937f67dc86805 100644 --- a/reader.go +++ b/reader.go @@ -3,6 +3,7 @@ import ( "context" "errors" + "fmt" "io" "sync" @@ -229,6 +230,15 @@ r.log(log.Fstr("error reading torrent %s piece %d offset %d, %d bytes: %v", r.t.infoHash.HexString(), firstPieceIndex, firstPieceOffset, len(b1), err)) if !r.t.updatePieceCompletion(firstPieceIndex) { r.log(log.Fstr("piece %d completion unchanged", firstPieceIndex)) + } + // Update the rest of the piece completions in the readahead window, without alerting to + // changes (since only the first piece, the one above, could have generated the read error + // we're currently handling). + if r.pieces.begin != firstPieceIndex { + panic(fmt.Sprint(r.pieces.begin, firstPieceIndex)) + } + for index := r.pieces.begin + 1; index < r.pieces.end; index++ { + r.t.updatePieceCompletion(index) } r.t.cl.unlock() }