]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix data race setting v2 piece hash
authorMatt Joiner <anacrolix@gmail.com>
Mon, 25 Mar 2024 02:35:53 +0000 (13:35 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 25 Mar 2024 02:35:53 +0000 (13:35 +1100)
piece.go

index 604da29807dbbea2b26bd5b9d2707422a0c063b8..5b2a1f3b60f328e2e86f3a964a995120fa2b8a30 100644 (file)
--- 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)
        }