Skip to content

Commit

Permalink
Merge pull request #2376 from hashicorp/b-fix-restore-errors
Browse files Browse the repository at this point in the history
Fix two issues during client restore state
  • Loading branch information
dadgar committed Feb 28, 2017
2 parents ca97b37 + 4826d84 commit 243c084
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,18 @@ func (r *TaskRunner) run() {
var stopCollection chan struct{}
var handleWaitCh chan *dstructs.WaitResult

// If we already have a handle, populate the stopCollection and handleWaitCh
// to fix the invariant that it exists.
r.handleLock.Lock()
handleEmpty := r.handle == nil
r.handleLock.Unlock()

if !handleEmpty {
stopCollection = make(chan struct{})
go r.collectResourceUsageStats(stopCollection)
handleWaitCh = r.handle.WaitCh()
}

for {
// Do the prestart activities
prestartResultCh := make(chan bool, 1)
Expand All @@ -895,7 +907,6 @@ func (r *TaskRunner) run() {
r.handleLock.Lock()
handleEmpty := r.handle == nil
r.handleLock.Unlock()

if handleEmpty {
startErr := r.startTask()
r.restartTracker.SetStartError(startErr)
Expand All @@ -909,14 +920,14 @@ func (r *TaskRunner) run() {
r.runningLock.Lock()
r.running = true
r.runningLock.Unlock()
}

if stopCollection == nil {
stopCollection = make(chan struct{})
go r.collectResourceUsageStats(stopCollection)
}
if stopCollection == nil {
stopCollection = make(chan struct{})
go r.collectResourceUsageStats(stopCollection)
}

handleWaitCh = r.handle.WaitCh()
handleWaitCh = r.handle.WaitCh()
}

case waitRes := <-handleWaitCh:
if waitRes == nil {
Expand Down

0 comments on commit 243c084

Please sign in to comment.