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.
This commit is contained in:
Matt Joiner 2021-10-27 15:14:11 +11:00
parent eb2fc6dbef
commit f2e9eeba3b
1 changed files with 3 additions and 0 deletions

View 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