Skip to content

Commit

Permalink
Merge pull request #1305 from aaronlehmann/restart-race
Browse files Browse the repository at this point in the history
orchestrator: Avoid restarting a task that has already been restarted
  • Loading branch information
aaronlehmann authored Aug 3, 2016
2 parents bf3c4f7 + 1f40cec commit f3bcaff
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions manager/orchestrator/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package orchestrator

import (
"container/list"
"errors"
"sync"
"time"

Expand Down Expand Up @@ -76,6 +77,9 @@ func (r *RestartSupervisor) waitRestart(ctx context.Context, oldDelay *delayedSt
if t == nil {
return nil
}
if t.DesiredState > api.TaskStateRunning {
return nil
}
service := store.GetService(tx, t.ServiceID)
if service == nil {
return nil
Expand Down Expand Up @@ -108,6 +112,13 @@ func (r *RestartSupervisor) Restart(ctx context.Context, tx store.Tx, cluster *a
}
r.mu.Unlock()

// Sanity check: was the task shut down already by a separate call to
// Restart? If so, we must avoid restarting it, because this will create
// an extra task. This should never happen unless there is a bug.
if t.DesiredState > api.TaskStateRunning {
return errors.New("Restart called on task that was already shut down")
}

t.DesiredState = api.TaskStateShutdown
err := store.UpdateTask(tx, &t)
if err != nil {
Expand Down

0 comments on commit f3bcaff

Please sign in to comment.