Skip to content

Commit

Permalink
Fix data race setting v2 piece hash
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Mar 25, 2024
1 parent 60d79eb commit d17250b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion piece.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d17250b

Please sign in to comment.