Skip to content

Commit 038427b

Browse files
authored
Fix data race in hash-based sync (#2159)
1 parent f561162 commit 038427b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/zc_traverser_local.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ func (t *localTraverser) prepareHashingThreads(preprocessor objectMorpher, proce
487487
return err
488488
}
489489
}
490+
processor = mutexProcessor(processor)
490491

491492
// spin up hashing threads
492493
for i := 0; i < hashingThreadCount; i++ {
@@ -575,7 +576,7 @@ func (t *localTraverser) prepareHashingThreads(preprocessor objectMorpher, proce
575576
noMetdata,
576577
"", // Local has no such thing as containers
577578
),
578-
mutexProcessor(processor),
579+
processor, // the original processor is wrapped in the mutex processor.
579580
)
580581
_, err = getProcessingError(err)
581582
if err != nil {
@@ -589,6 +590,7 @@ func (t *localTraverser) prepareHashingThreads(preprocessor objectMorpher, proce
589590
// wrap the processor, try to grab hashes, or defer processing to the goroutines
590591
hashingProcessor = func(storedObject StoredObject) error {
591592
if storedObject.entityType != common.EEntityType.File() {
593+
// the original processor is wrapped in the mutex processor.
592594
return processor(storedObject) // no process folders
593595
}
594596

@@ -603,6 +605,7 @@ func (t *localTraverser) prepareHashingThreads(preprocessor objectMorpher, proce
603605
switch err {
604606
case ErrorNoHashPresent, ErrorHashNoLongerValid, ErrorHashNotCompatible:
605607
glcm.Info("No usable hash is present for " + fullPath + ". Will transfer if not present at destination.")
608+
// the original processor is wrapped in the mutex processor.
606609
return processor(storedObject) // There is no hash data, so this file will be overwritten (in theory).
607610
case ErrorHashAsyncCalculation:
608611
return nil // File will be processed later
@@ -620,7 +623,8 @@ func (t *localTraverser) prepareHashingThreads(preprocessor objectMorpher, proce
620623
}
621624

622625
// delay the mutex until after potentially long-running operations
623-
return mutexProcessor(processor)(storedObject)
626+
// the original processor is wrapped in the mutex processor.
627+
return processor(storedObject)
624628
}
625629

626630
return finalizer, hashingProcessor

0 commit comments

Comments
 (0)