piece.go | 5 ++++- diff --git a/piece.go b/piece.go index 604da29807dbbea2b26bd5b9d2707422a0c063b8..5b2a1f3b60f328e2e86f3a964a995120fa2b8a30 100644 --- a/piece.go +++ b/piece.go @@ -286,7 +286,10 @@ // Sets the v2 piece hash, queuing initial piece checks if appropriate. func (p *Piece) setV2Hash(v2h [32]byte) { // See Torrent.onSetInfo. We want to trigger an initial check if appropriate, if we didn't yet // have a piece hash (can occur with v2 when we don't start with piece layers). - if !p.hashV2.Set(v2h).Ok && p.hash == nil { + p.t.storageLock.Lock() + oldV2Hash := p.hashV2.Set(v2h) + p.t.storageLock.Unlock() + if !oldV2Hash.Ok && p.hash == nil { p.t.updatePieceCompletion(p.index) p.t.queueInitialPieceCheck(p.index) }