Skip to content

Commit

Permalink
Merge pull request #7663 from hashicorp/b-taskrunner-shutdown_delay
Browse files Browse the repository at this point in the history
Run task shutdown_delay regardless of service registration
  • Loading branch information
drewbailey committed Apr 13, 2020
2 parents 092456b + f207abd commit aab5233
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

BUG FIXES:

* core: Fixed a bug that only ran a task `shutdown_delay` if the task had a registered service [[GH-7663](https://github.com/hashicorp/nomad/issues/7663)]
* vault: Upgrade http2 library to fix Vault API calls that fail with `http2: no cached connection was available` [[GH-7673](https://github.com/hashicorp/nomad/issues/7673)]

## 0.11.0 (April 8, 2020)
Expand Down
14 changes: 0 additions & 14 deletions client/allocrunner/taskrunner/service_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"sync"
"time"

log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
Expand Down Expand Up @@ -40,7 +39,6 @@ type serviceHook struct {
logger log.Logger

// The following fields may be updated
delay time.Duration
driverExec tinterfaces.ScriptExecutor
driverNet *drivers.DriverNetwork
canary bool
Expand All @@ -64,7 +62,6 @@ func newServiceHook(c serviceHookConfig) *serviceHook {
taskName: c.task.Name,
services: c.task.Services,
restarter: c.restarter,
delay: c.task.ShutdownDelay,
}

if res := c.alloc.AllocatedResources.Tasks[c.task.Name]; res != nil {
Expand Down Expand Up @@ -140,7 +137,6 @@ func (h *serviceHook) updateHookFields(req *interfaces.TaskUpdateRequest) error
}

// Update service hook fields
h.delay = task.ShutdownDelay
h.taskEnv = req.TaskEnv
h.services = task.Services
h.networks = networks
Expand All @@ -156,16 +152,6 @@ func (h *serviceHook) PreKilling(ctx context.Context, req *interfaces.TaskPreKil
// Deregister before killing task
h.deregister()

// If there's no shutdown delay, exit early
if h.delay == 0 {
return nil
}

h.logger.Debug("waiting before killing task", "shutdown_delay", h.delay)
select {
case <-ctx.Done():
case <-time.After(h.delay):
}
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,14 @@ func (tr *TaskRunner) handleKill() *drivers.ExitResult {
// Run the pre killing hooks
tr.preKill()

// Wait for task ShutdownDelay after running prekill hooks
// This allows for things like service de-registration to run
// before waiting to kill task
if delay := tr.Task().ShutdownDelay; delay != 0 {
tr.logger.Debug("waiting before killing task", "shutdown_delay", delay)
time.Sleep(delay)
}

// Tell the restart tracker that the task has been killed so it doesn't
// attempt to restart it.
tr.restartTracker.SetKilled()
Expand Down

0 comments on commit aab5233

Please sign in to comment.