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

Backport of client: ensure task only runs with prestart hooks into release/1.5.x #18669

Conversation

hc-github-team-nomad-core
Copy link
Contributor

Backport

This PR is auto-generated from #18662 to be assessed for backporting due to the inclusion of the label backport/1.5.x.

The below text is copied from the body of the original PR.


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.

Some other implementations ideas I considered:

  1. Move the check for shouldShutdown() from within prestart() to before it is called. I think this would be more or less equivalent to this approach.
  2. Create a read lock on the task runner alloc so that shouldShutdown() is guaranteed not to change while prestart() runs and the task starts. This is probably the most "correct" approach, but since shouldShutdown() can only transition from false to true, checking it again after prestart() seems enough.

Closes #18659


Overview of commits

@hc-github-team-nomad-core hc-github-team-nomad-core force-pushed the backport/b-prevent-task-start-without-prestart/physically-selected-turtle branch 2 times, most recently from eb4fae8 to 3c56a4c Compare October 5, 2023 14:17
@vercel vercel bot temporarily deployed to Preview – nomad October 5, 2023 14:22 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui October 5, 2023 14:29 Inactive
@lgfa29 lgfa29 merged commit 1ba2788 into release/1.5.x Oct 5, 2023
23 of 25 checks passed
@lgfa29 lgfa29 deleted the backport/b-prevent-task-start-without-prestart/physically-selected-turtle branch October 5, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants