client.go | 8 ++++++-- diff --git a/client.go b/client.go index 61556967ea9e76c82c79af12861832bbd9d68447..115a9904bb890b59a5cc95c2a119c00ada03b2b1 100644 --- a/client.go +++ b/client.go @@ -1502,12 +1502,12 @@ } func (cl *Client) verifyPiece(t *torrent, index pp.Integer) { cl.mu.Lock() + defer cl.mu.Unlock() p := t.Pieces[index] for p.Hashing { cl.event.Wait() } if t.isClosed() { - cl.mu.Unlock() return } p.Hashing = true @@ -1515,9 +1515,13 @@ p.QueuedForHash = false cl.mu.Unlock() sum := t.HashPiece(index) cl.mu.Lock() + select { + case <-t.closing: + return + default: + } p.Hashing = false cl.pieceHashed(t, index, sum == p.Hash) - cl.mu.Unlock() } func (me *Client) Torrents() (ret []*torrent) {