-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
task runner to avoid running task if terminal #5890
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,6 +394,22 @@ func (tr *TaskRunner) Run() { | |
defer close(tr.waitCh) | ||
var result *drivers.ExitResult | ||
|
||
tr.stateLock.RLock() | ||
dead := tr.state.State == structs.TaskStateDead | ||
tr.stateLock.RUnlock() | ||
|
||
// if restoring a dead task, ensure that task is cleared and all post hooks | ||
// are called without additional state updates | ||
if dead { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here I only check if the task itself is dead - I suspect we should be checking if the restore alloc had a terminated alloc state. I suspect that an alloc with tasks with mixed status causes some some complications? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this is the right behavior. An alloc is considering running if one task completes, and all allocs will be killed if leader task dies or a task failed enough times. Until that happens, we should treat other tasks as running. |
||
// clear driver handle if it was successfully restored on | ||
// already dead task | ||
tr.clearDriverHandle() | ||
if err := tr.stop(); err != nil { | ||
tr.logger.Error("stop failed on terminal task", "error", err) | ||
} | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may also want to call
At this point I do not think anything will have told the sidecar service to exit despite its leader dying. If you call This could be done in a followup PR as well since I think your changes improve the situation. |
||
} | ||
|
||
// Updates are handled asynchronously with the other hooks but each | ||
// triggered update - whether due to alloc updates or a new vault token | ||
// - should be handled serially. | ||
|
@@ -899,7 +915,7 @@ func (tr *TaskRunner) Restore() error { | |
} | ||
|
||
alloc := tr.Alloc() | ||
if alloc.TerminalStatus() || alloc.Job.Type == structs.JobTypeSystem { | ||
if tr.state.State == structs.TaskStateDead || alloc.TerminalStatus() || alloc.Job.Type == structs.JobTypeSystem { | ||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name/comment mismatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test looks good, but just to verify:
-race
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it passes with
-race
and was failing before - here is a sample build failure [1] when adding test alone. The failure snippet is:As seen in stack trace, we fail in line 204 [1] because AR.wait() times out, then times out again in destroy defer call.
I'll follow up in another PR to change the destroy defer call so that it errors rather than blocks indefinitely on failures to make tracking these errors better.
[1] https://travis-ci.org/hashicorp/nomad/jobs/553113545
[2] https://github.com/hashicorp/nomad/compare/b-dont-start-completed-allocs-2-test-only?expand=1
[3] https://github.com/hashicorp/nomad/compare/b-dont-start-completed-allocs-2-test-only?expand=1#diff-41decefd2f35059b5c0b95166e275653R204