fix race condition in managedAddFileToRepairState

parent 5a799ac5
......@@ -105,9 +105,9 @@ func (cs *chunkStatus) numGaps(rs *repairState) int {
func (r *Renter) managedAddFileToRepairState(rs *repairState, file *file) {
// Check that the file is being tracked, and therefore candidate for
// repair.
file.mu.Lock()
file.mu.RLock()
_, exists := r.tracking[file.name]
file.mu.Unlock()
file.mu.RUnlock()
if !exists {
return
}
......@@ -132,7 +132,13 @@ func (r *Renter) managedAddFileToRepairState(rs *repairState, file *file) {
}
// Iterate through each contract and figure out which pieces are available.
for _, contract := range file.contracts {
file.mu.RLock()
var fileContracts []fileContract
for _, c := range file.contracts {
fileContracts = append(fileContracts, c)
}
file.mu.RUnlock()
for _, contract := range fileContracts {
// Check whether this contract is offline. Even if the contract is
// offline, we want to record that the chunk has attempted to use this
// contract.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment