{"record":{"id":"5278e114404d6cbc","repo":"hashicorp/nomad","slug":"task-q-is-not-running","errorCode":null,"errorMessage":"task %q is not running.","messagePattern":"task %q is not running\\.","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"client/alloc_endpoint.go","lineNumber":367,"sourceCode":"\t\treturn code, err\n\t}\n\n\t// Check that the task is there\n\ttaskState := allocState.TaskStates[req.Task]\n\tif taskState == nil {\n\t\treturn new(int64(400)), fmt.Errorf(\"unknown task name %q\", req.Task)\n\t}\n\n\tif taskState.StartedAt.IsZero() {\n\t\treturn new(int64(404)), fmt.Errorf(\"task %q not started yet.\", req.Task)\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\th := ar.GetTaskExecHandler(req.Task)\n\tif h == nil {\n\t\treturn new(int64(404)), fmt.Errorf(\"task %q is not running.\", req.Task)\n\t}\n\n\terr = h(ctx, req.Cmd, req.Tty, newExecStream(decoder, encoder))\n\tif err != nil {\n\t\tcode := new(int64(500))\n\t\treturn code, err\n\t}\n\n\treturn nil, nil\n}\n\n// newExecStream returns a new exec stream as expected by drivers that interpolate with RPC streaming format\nfunc newExecStream(decoder *codec.Decoder, encoder *codec.Encoder) drivers.ExecTaskStream {\n\tbuf := new(bytes.Buffer)\n\treturn &execStream{\n\t\tdecoder: decoder,\n\n\t\tbuf:        buf,","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/alloc_endpoint.go#L349-L385","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before\nclient.Exec(allocID, \"web\", []string{\"sh\"})\n// after\nalloc, _, _ := client.Allocations().Info(allocID, nil)\nif alloc.TaskStates[\"web\"].State == structs.TaskStateRunning {\n  client.Exec(allocID, \"web\", []string{\"sh\"})\n}","handlingStrategy":"retry","validationCode":"alloc, _, _ := client.Allocations().Info(allocID, nil)\nts := alloc.TaskStates[taskName]\nrunning := ts != nil && ts.State == structs.TaskStateRunning && !ts.Restarts > 0 == false // check events for recent restarts","typeGuard":"func taskRunning(alloc *api.Allocation, task string) bool {\n  ts := alloc.TaskStates[task]\n  return ts != nil && ts.State == structs.TaskStateRunning\n}","tryCatchPattern":"code, err := client.Allocations().Exec(...)\nif err != nil && strings.Contains(err.Error(), \"is not running\") {\n  // task crashed/restarting: inspect events, fix crash, or retry with backoff\n}","preventionTips":["Check task events/restart counts before exec","Avoid exec during deployments and reschedules","Fix crashing tasks promptly; exec implies a live process"],"tags":["nomad","exec","process-lifecycle"],"backgroundTag":"task-not-running","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}