From d17250bc125e9f02fd16411461e37192430fc85c Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 25 Mar 2024 13:35:53 +1100 Subject: [PATCH] Fix data race setting v2 piece hash --- piece.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/piece.go b/piece.go index 604da29807..5b2a1f3b60 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) }