{"record":{"id":"d148e3b4226ab43c","repo":"hashicorp/nomad","slug":"failed-to-restart-task-q-w","errorCode":null,"errorMessage":"Failed to restart task %q: %w","messagePattern":"Failed to restart task %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/job_restart.go","lineNumber":921,"sourceCode":"\tvar restarts multierror.Group\n\tfor task := range c.tasks.Items() {\n\t\tif !alloc.HasTask(task) {\n\t\t\tcontinue\n\t\t}\n\n\t\tc.Ui.Output(fmt.Sprintf(\n\t\t\t\"    %s: Restarting task %q in allocation %q for group %q\",\n\t\t\tformatTime(time.Now()),\n\t\t\ttask,\n\t\t\tshortAllocID,\n\t\t\talloc.TaskGroup,\n\t\t))\n\n\t\trestarts.Go(func(taskName string) func() error {\n\t\t\treturn func() error {\n\t\t\t\terr := c.client.Allocations().Restart(&api.Allocation{ID: alloc.ID}, taskName, nil)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"Failed to restart task %q: %w\", taskName, err)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}(task))\n\t}\n\treturn restarts.Wait().ErrorOrNil()\n}\n\n// stopAlloc stops an allocation and blocks until the replacement allocation is\n// running.\nfunc (c *JobRestartCommand) stopAlloc(alloc AllocationListStubWithJob) error {\n\tshortAllocID := limit(alloc.ID, c.length)\n\n\tc.Ui.Output(fmt.Sprintf(\n\t\t\"    %s: Rescheduling allocation %q for group %q\",\n\t\tformatTime(time.Now()),\n\t\tshortAllocID,\n\t\talloc.TaskGroup,","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/job_restart.go#L903-L939","documentation":"Per-task restart via client.Allocations().Restart(alloc, taskName, nil) failed; the error is wrapped as 'Failed to restart task <name>: <cause>' and returned through an errgroup so all tasks restart concurrently.","triggerScenarios":"The Restart API call for a specific task returns an error — e.g. alloc not running, task not found in the alloc, driver error, or RPC failure to the client node.","commonSituations":"Task already dead/failed so restart is invalid; node disconnected during restart; stale alloc ID after a reschedule; insufficient ACL permissions.","solutions":["Inspect nomad alloc status <alloc-id> to confirm the task is running","Check the client node logs for the driver-level restart error","Verify the alloc ID is current (job may have been rescheduled)","Retry once the node/agent is reachable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"alloc, _, err := client.Allocations().Info(alloc.ID, nil)\nif err != nil {\n    return err\n}\ntaskState, ok := alloc.TaskStates[taskName]\nif !ok || taskState.State != \"running\" {\n    return fmt.Errorf(\"task %s not running in alloc %s\", taskName, alloc.ID)\n}","typeGuard":"func taskRunning(a *api.Allocation, task string) bool {\n    ts, ok := a.TaskStates[task]\n    return ok && ts.State == \"running\"\n}","tryCatchPattern":"err := c.client.Allocations().Restart(&api.Allocation{ID: alloc.ID}, task, nil)\nif err != nil {\n    if isRetryable(err) { return retryWithBackoff() }\n    return fmt.Errorf(\"non-retryable restart failure: %w\", err)\n}","preventionTips":["Verify task state is running before restart","Refresh the alloc from the API to avoid stale IDs","Retry transient RPC failures with backoff"],"tags":["nomad","api","task","restart","concurrency"],"backgroundTag":"task-restart-failed","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"}