{"record":{"id":"d017ada52453e20c","repo":"hashicorp/nomad","slug":"exec-task-timed-out-v","errorCode":null,"errorMessage":"exec task timed out: %v","messagePattern":"exec task timed out: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/taskrunner/driver_handle.go","lineNumber":114,"sourceCode":"\tif !ok {\n\t\treturn fmt.Errorf(\"task driver does not support exec\")\n\t}\n\n\texecOpts, doneCh := drivers.StreamToExecOptions(\n\t\tctx, command, tty, stream)\n\n\tresult, err := d.ExecTaskStreaming(ctx, h.taskID, execOpts)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\texecOpts.Stdout.Close()\n\texecOpts.Stderr.Close()\n\n\tselect {\n\tcase err = <-doneCh:\n\tcase <-ctx.Done():\n\t\terr = fmt.Errorf(\"exec task timed out: %v\", ctx.Err())\n\t}\n\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn stream.Send(drivers.NewExecStreamingResponseExit(result.ExitCode))\n}\n\nfunc (h *DriverHandle) Network() *drivers.DriverNetwork {\n\treturn h.net\n}\n","sourceCodeStart":96,"sourceCodeEnd":127,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/taskrunner/driver_handle.go#L96-L127","documentation":"In DriverHandle.ExecStreaming, after streaming stdin/stdout/stderr, the handler waits on doneCh (signaled by the driver when the exec finishes) and races it against ctx.Done(). If the context is cancelled or its deadline expires first, the exec is considered timed out and this error wraps ctx.Err().","triggerScenarios":"The exec session in the task did not complete before the caller's context deadline/cancellation; ctx.Done() fires while waiting on doneCh.","commonSituations":"'nomad alloc exec' with a command that hangs longer than the client timeout; an interactive exec session left idle past a deadline; slow command inside a resource-starved container.","solutions":["Increase the caller's context deadline/timeout for long-running exec commands","Verify the exec'd command actually terminates (avoid interactive commands in scripts)","Check task resource starvation (CPU limits) that makes the command slow","Cancel intentionally and re-run with a larger timeout if this was expected"],"exampleFix":"// before\nctx := context.Background()\n// after: give the exec more time\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()","handlingStrategy":"retry","validationCode":"// pick a deadline that comfortably exceeds expected command runtime\ndeadline := time.Now().Add(5 * time.Minute)\nif deadline.Before(time.Now().Add(expectedRuntime)) {\n    return errors.New(\"configured exec timeout too small for this command\")\n}","typeGuard":null,"tryCatchPattern":"err := handle.ExecStreaming(ctx, cmd, tty, stream)\nif err != nil && strings.Contains(err.Error(), \"exec task timed out\") {\n    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)\n    defer cancel()\n    err = handle.ExecStreaming(ctx, cmd, tty, stream) // retry with longer deadline\n}","preventionTips":["Set exec context deadlines above worst-case command runtime","Avoid interactive commands in automated exec calls","Watch for CPU-starved tasks that slow execution","Cancel idle interactive sessions deliberately instead of letting them time out"],"tags":["exec","timeout","context"],"backgroundTag":"exec-timeout","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"}