From f2e9eeba3b0cf5447836425104dde25dfdea425d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 27 Oct 2021 15:14:11 +1100 Subject: [PATCH] Check if torrent is closed before handling peer request data read failures Should fix panics using storage after its been closed, like in https://github.com/anacrolix/torrent/runs/4017475163. --- peerconn.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/peerconn.go b/peerconn.go index 91ef37e6..c85135dc 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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