hashicorp/nomad · error
task %q is not running.
Error message
task %q is not running.
What it means
After confirming the task exists and started, execImpl fetches the task's live exec handler via ar.GetTaskExecHandler. A nil handler means the driver-side process is not currently accepting exec (process exited, restarting, or the handler was never registered), so the endpoint returns HTTP 404. The task may have started but is no longer running.
Source
Thrown at client/alloc_endpoint.go:367
return code, err
}
// Check that the task is there
taskState := allocState.TaskStates[req.Task]
if taskState == nil {
return new(int64(400)), fmt.Errorf("unknown task name %q", req.Task)
}
if taskState.StartedAt.IsZero() {
return new(int64(404)), fmt.Errorf("task %q not started yet.", req.Task)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
h := ar.GetTaskExecHandler(req.Task)
if h == nil {
return new(int64(404)), fmt.Errorf("task %q is not running.", req.Task)
}
err = h(ctx, req.Cmd, req.Tty, newExecStream(decoder, encoder))
if err != nil {
code := new(int64(500))
return code, err
}
return nil, nil
}
// newExecStream returns a new exec stream as expected by drivers that interpolate with RPC streaming format
func newExecStream(decoder *codec.Decoder, encoder *codec.Encoder) drivers.ExecTaskStream {
buf := new(bytes.Buffer)
return &execStream{
decoder: decoder,
buf: buf,View on GitHub (pinned to 482b49bf1a)
Solutions
- Check `nomad alloc status <alloc-id>` and recent task events for crashes/restarts
- Fix the underlying task crash, then retry exec while the task is running
- Retry the exec with backoff if racing a restart
- Verify the driver supports exec for this task
Example fix
// before
client.Exec(allocID, "web", []string{"sh"})
// after
alloc, _, _ := client.Allocations().Info(allocID, nil)
if alloc.TaskStates["web"].State == structs.TaskStateRunning {
client.Exec(allocID, "web", []string{"sh"})
} Defensive patterns
Strategy: retry
Validate before calling
alloc, _, _ := client.Allocations().Info(allocID, nil) ts := alloc.TaskStates[taskName] running := ts != nil && ts.State == structs.TaskStateRunning && !ts.Restarts > 0 == false // check events for recent restarts
Type guard
func taskRunning(alloc *api.Allocation, task string) bool {
ts := alloc.TaskStates[task]
return ts != nil && ts.State == structs.TaskStateRunning
} Try / catch
code, err := client.Allocations().Exec(...)
if err != nil && strings.Contains(err.Error(), "is not running") {
// task crashed/restarting: inspect events, fix crash, or retry with backoff
} Prevention
- Check task events/restart counts before exec
- Avoid exec during deployments and reschedules
- Fix crashing tasks promptly; exec implies a live process
When it happens
Trigger: Exec'ing into a task whose process has crashed or exited; the task is restarting after a failed health check; the driver does not support exec handlers; racing with a task stop/kill.
Common situations: Exec into a task that just OOM-killed or crashed; task in a restart loop; exec during a deployment replacing the allocation; running exec against a task type whose driver lacks exec support (e.g. some raw_exec/java configurations).
Related errors
- no exec command is configured
- unknown task name %q
- task %q not started yet.
- %w: %v; see: <https://developer.hashicorp.com/nomad/s/envoy-
- failed to marshal command into json: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/5278e114404d6cbc.
Report an issue: GitHub.