{"record":{"id":"4463f996bbaaef19","repo":"hashicorp/nomad","slug":"failed-to-inspect-exit-code-of-exec-object-w","errorCode":null,"errorMessage":"failed to inspect exit code of exec object: %w","messagePattern":"failed to inspect exit code of exec object: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/handle.go","lineNumber":121,"sourceCode":"\tstartOpts := mclient.ExecAttachOptions{TTY: false}\n\n\t// hijack exec output streams\n\thijacked, err := h.dockerClient.ExecAttach(ctx, exec.ID, startOpts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to attach to exec object: %w\", err)\n\t}\n\n\t_, err = stdcopy.StdCopy(stdout, stderr, hijacked.Reader)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer hijacked.Close()\n\n\texecResult.Stdout = stdout.Bytes()\n\texecResult.Stderr = stderr.Bytes()\n\tres, err := h.dockerClient.ExecInspect(ctx, exec.ID, mclient.ExecInspectOptions{})\n\tif err != nil {\n\t\treturn execResult, fmt.Errorf(\"failed to inspect exit code of exec object: %w\", err)\n\t}\n\n\texecResult.ExitResult.ExitCode = res.ExitCode\n\treturn execResult, nil\n}\n\nfunc (h *taskHandle) Signal(ctx context.Context, s string) error {\n\t_, err := signals.Parse(s)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse signal: %v\", err)\n\t}\n\n\t_, err = h.dockerClient.ContainerKill(ctx, h.containerID, mclient.ContainerKillOptions{Signal: s})\n\treturn err\n}\n\n// parseSignal interprets the signal name into an os.Signal. If no name is\n// provided, the docker driver defaults to SIGTERM. If the OS is Windows and","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/handle.go#L103-L139","documentation":"Once the exec's output has been copied, the driver inspects the exec instance to read its exit code via ExecInspect. If that inspection call fails, the command's output is returned but the exit status is unknown and this wrapped error is reported.","triggerScenarios":"h.dockerClient.ExecInspect(ctx, exec.ID, ...) errors: exec record already pruned by the engine (execs are removed shortly after completion), daemon unreachable, or the container/exec was removed concurrently.","commonSituations":"Long-running exec finishing while the Docker daemon is restarted; Docker versions where completed execs are garbage-collected quickly; querying exit code of an exec whose container was removed by an auto-remove/stop race.","solutions":["Check the captured stdout/stderr in execResult for the actual command output — the command may have run fine; only the exit code is missing.","Re-run the command; a fresh exec will have an inspectable exit code.","Check Docker daemon availability and logs if errors are persistent.","Upgrade the docker driver/engine if execs are being pruned before inspection (known garbage-collection races in older engines)."],"exampleFix":"// before: assuming failure means command failed\nres, err := client.ExecInspect(...)\n// after: treat as unknown exit code, output still valid\nif err != nil {\n    // inspect execResult.Stdout/Stderr from the returned execResult before retrying\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := driver.ExecTask(ctx, taskID, opts)\nif err != nil && strings.Contains(err.Error(), \"failed to inspect exit code of exec object\") {\n    // execResult may still carry stdout/stderr; use them before deciding to rerun\n    if res != nil && len(res.Stdout) > 0 {\n        log.Printf(\"output captured despite exit-code loss: %s\", res.Stdout)\n    }\n}","preventionTips":["Treat this as 'unknown exit code', not necessarily command failure.","Keep Docker daemons stable (avoid restarts during exec).","Capture and inspect the returned stdout/stderr before retrying."],"tags":["docker-driver","exec","exit-code"],"backgroundTag":"docker-exec-inspect-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"}