mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
client: ensure task only runs with prestart hooks (#18662)
Since the allocation in the task runner is updated in a separate goroutine, a race condition may happen where the task is started but the prestart hooks are skipped because the allocation became terminal. Checking for a terminal allocation before proceeding with the task start ensures the task only runs if the prestart hooks are also executed. Since `shouldShutdown()` only uses terminal allocation status, it remains `true` after the first transition, so it's safe to check it again after the prestart hooks as it will never revert to `false`.
This commit is contained in:
3
.changelog/18662.txt
Normal file
3
.changelog/18662.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
client: prevent tasks from starting without the prestart hooks running
|
||||
```
|
||||
@@ -599,6 +599,12 @@ MAIN:
|
||||
goto RESTART
|
||||
}
|
||||
|
||||
// Check for a terminal allocation once more before proceeding as the
|
||||
// prestart hooks may have been skipped.
|
||||
if tr.shouldShutdown() {
|
||||
break MAIN
|
||||
}
|
||||
|
||||
select {
|
||||
case <-tr.killCtx.Done():
|
||||
break MAIN
|
||||
|
||||
Reference in New Issue
Block a user