Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two issues during client restore state #2376

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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