From: Matt Joiner Date: Mon, 25 Mar 2024 02:35:53 +0000 (+1100) Subject: Fix data race setting v2 piece hash X-Git-Tag: v1.56.0~28 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d17250bc125e9f02fd16411461e37192430fc85c;p=btrtrc.git Fix data race setting v2 piece hash --- diff --git a/piece.go b/piece.go index 604da298..5b2a1f3b 100644 --- a/piece.go +++ b/piece.go @@ -286,7 +286,10 @@ func (p *Piece) mustGetOnlyFile() *File { 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) }