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

Run task shutdown_delay regardless of service registration #7663

Merged
merged 3 commits into from
Apr 13, 2020

Conversation

drewbailey
Copy link
Contributor

@drewbailey drewbailey commented Apr 8, 2020

task shutdown_delay will currently only run if there are registered
services for the task. This implementation detail isn't explicity stated
anywhere and is defined outside of the service stanza.

This change moves shutdown_delay to be evaluated after prekill hooks are
run, outside of any task runner hooks.

fixes #7271

@drewbailey drewbailey requested review from schmichael and notnoop April 8, 2020 15:20
Copy link
Member

@nickethier nickethier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comes out a lot cleaner!

// before waiting to kill task
if delay := tr.Task().ShutdownDelay; delay != 0 {
tr.logger.Debug("waiting before killing task", "shutdown_delay", delay)
<-time.After(delay)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the equivalent of time.Sleep(delay).

Also, should we check for tr.shutdownCtx and exit? Depending on long this command is, we may lock up the agent until process is killed before agent exits. This matches current behavior, so not too much of a concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think shutdownCtx is used to exit task runner without affecting the task state, so handleKill won't be invoked by shutdownCtx, killCtx.Done() case invokes handleKill so I think we are stuck waiting

Copy link
Member

@schmichael schmichael Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's manually (automated around timing is hard and false negative/positive prone) test your assertion and leave the result in a comment. I would imagine everyone who comes across this code in the future will wonder why a context isn't also checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-dev agent running a job with shutdown delay of 50s hangs for 50 before finishing shutdown

^C==> Caught signal: interrupt
    2020-04-10T11:48:11.367-0400 [DEBUG] http: shutting down http server
    2020-04-10T11:48:11.367-0400 [INFO]  agent: requesting shutdown
    2020-04-10T11:48:11.367-0400 [INFO]  client: shutting down
    2020-04-10T11:48:11.367-0400 [DEBUG] client.alloc_runner.runner_hook.group_services: waiting before removing group service: alloc_id=160da727-bb2d-5ff1-d101-2bdbf6db2a12 shutdown_delay=50s

same job running on a client kill -9 pid exits immediately with job still running

→ docker ps
CONTAINER ID        IMAGE                                 COMMAND                 CREATED              STATUS              PORTS               NAMES
45f5de1841df        hashicorpnomad/counter-dashboard:v1   "./dashboard-service"   About a minute ago   Up About a minute   9002/tcp            dashboard-213af190-7ea9-d1ed-e58b-06219d0fdfec
9cb712bf23e5        hashicorpnomad/counter-api:v1         "./counting-service"    About a minute ago   Up About a minute   9001/tcp            web-213af190-7ea9-d1ed-e58b-06219d0fdfec

task shutdown_delay will currently only run if there are registered
services for the task. This implementation detail isn't explicity stated
anywhere and is defined outside of the service stanza.

This change moves shutdown_delay to be evaluated after prekill hooks are
run, outside of any task runner hooks.

just use time.sleep
@drewbailey drewbailey force-pushed the b-taskrunner-shutdown_delay branch from 3c322b8 to e288658 Compare April 10, 2020 15:14
CHANGELOG.md Outdated Show resolved Hide resolved
@drewbailey drewbailey merged commit aab5233 into master Apr 13, 2020
@drewbailey drewbailey deleted the b-taskrunner-shutdown_delay branch April 13, 2020 17:27
@djenriquez
Copy link

Sorry I'm a bit late on this PR, just saw it was merged, but question @drewbailey: since this is an additive check, should we expect tasks with both a group shutdown_delay and task shutdown_delay to in sum, wait both periods before actually exiting? The group shutdown_delay is handled in the pre-kill hooks right?

@drewbailey
Copy link
Contributor Author

Hey @djenriquez, yes, that is currently the case. I'll create a follow up ticket to ensure its properly called out in the docs.

@github-actions
Copy link

github-actions bot commented Jan 9, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow shutdown_delay to execute regardless of service registration
5 participants