Commit 460e9256 authored by Luke Champine's avatar Luke Champine Committed by GitHub

Merge pull request #1592 from NebulousLabs/renter-race

fix a race condition in the renter
parents 834664a2 cebcc418
......@@ -98,6 +98,15 @@ func (cs *chunkStatus) numGaps(rs *repairState) int {
// addFileToRepairState will take a file and add each of the incomplete chunks
// to the repair state, along with data about which pieces need attention.
func (r *Renter) addFileToRepairState(rs *repairState, file *file) {
// Check that the file is being tracked, and therefor candidate for repair.
file.mu.Lock()
_, exists := r.tracking[file.name]
file.mu.Unlock()
if !exists {
// File is not being tracked, don't add it to the repair state.
return
}
// Fetch the list of potential contracts from the repair state.
contracts := make([]types.FileContractID, 0)
for contract := range rs.activeWorkers {
......@@ -178,7 +187,9 @@ func (r *Renter) managedRepairIteration(rs *repairState) {
return
case file := <-r.newRepairs:
// TODO: This seems to be happening out of lock, investigate.
id := r.mu.Lock()
r.addFileToRepairState(rs, file)
r.mu.Unlock(id)
return
}
}
......@@ -398,7 +409,9 @@ func (r *Renter) managedWaitOnRepairWork(rs *repairState) {
select {
case finishedUpload = <-rs.resultChan:
case file := <-r.newRepairs:
id := r.mu.Lock()
r.addFileToRepairState(rs, file)
r.mu.Unlock(id)
return
case <-r.tg.StopChan():
return
......@@ -449,7 +462,7 @@ func (r *Renter) threadedQueueRepairs() {
}
r.mu.RUnlock(id)
// Add files one at a time.
// Add files.
for _, file := range files {
// Send the file down the repair channel.
select {
......@@ -457,19 +470,12 @@ func (r *Renter) threadedQueueRepairs() {
case <-r.tg.StopChan():
return
}
// Wait 5 seconds before going to the next file.
select {
case <-time.After(time.Second * 5):
case <-r.tg.StopChan():
return
}
}
// Chill out for an extra 5 minutes before going through the files
// Chill out for an extra 15 minutes before going through the files
// again.
select {
case <-time.After(time.Minute * 5):
case <-time.After(time.Minute * 15):
case <-r.tg.StopChan():
return
}
......
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