]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Check if torrent is closed before handling peer request data read failures
authorMatt Joiner <anacrolix@gmail.com>
Wed, 27 Oct 2021 04:14:11 +0000 (15:14 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 27 Oct 2021 04:14:11 +0000 (15:14 +1100)
Should fix panics using storage after its been closed, like in https://github.com/anacrolix/torrent/runs/4017475163.

peerconn.go

index 91ef37e601f27bf37a51b886f1658b88eb4f5d6f..c85135dc2c6a6a901eade4e0f0723e7c82ee25a8 100644 (file)
@@ -984,6 +984,9 @@ func (c *PeerConn) peerRequestDataReader(r Request, prs *peerRequestState) {
 // chunk sending, the way it used to work.
 func (c *PeerConn) peerRequestDataReadFailed(err error, r Request) {
        c.logger.WithDefaultLevel(log.Warning).Printf("error reading chunk for peer Request %v: %v", r, err)
+       if c.t.closed.IsSet() {
+               return
+       }
        i := pieceIndex(r.Index)
        if c.t.pieceComplete(i) {
                // There used to be more code here that just duplicated the following break. Piece