{"record":{"id":"b87089f7f7c946cb","repo":"hashicorp/nomad","slug":"failed-to-set-command-tty-v","errorCode":null,"errorMessage":"failed to set command tty: %v","messagePattern":"failed to set command tty: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/shared/executor/exec_utils.go","lineNumber":56,"sourceCode":"\tprocessWait func() (*os.ProcessState, error)\n}\n\nfunc (e *execHelper) run(ctx context.Context, tty bool, stream drivers.ExecTaskStream) error {\n\tif tty {\n\t\treturn e.runTTY(ctx, stream)\n\t}\n\treturn e.runNoTTY(ctx, stream)\n}\n\nfunc (e *execHelper) runTTY(ctx context.Context, stream drivers.ExecTaskStream) error {\n\tptyF, tty, err := e.newTerminal()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open a tty: %v\", err)\n\t}\n\tdefer tty.Close()\n\n\tif err := e.setTTY(tty); err != nil {\n\t\treturn fmt.Errorf(\"failed to set command tty: %v\", err)\n\t}\n\tif err := e.processStart(); err != nil {\n\t\treturn fmt.Errorf(\"failed to start command: %v\", err)\n\t}\n\n\tvar wg sync.WaitGroup\n\terrCh := make(chan error, 3)\n\n\tpty, err := ptyF()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get pty: %v\", err)\n\t}\n\n\tdefer pty.Close()\n\twg.Add(1)\n\tgo handleStdin(e.logger, pty, stream, errCh)\n\t// when tty is on, stdout and stderr point to the same pty so only read once\n\tgo handleStdout(e.logger, pty, &wg, stream.Send, errCh)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/shared/executor/exec_utils.go#L38-L74","documentation":"After opening the pty, runTTY applies terminal settings (raw mode, window size) to the slave tty via setTTY(). If that configuration step fails, the executor wraps it as 'failed to set command tty' and the exec session fails even though the pty opened.","triggerScenarios":"setTTY fails — typically ioctl/termios errors applying raw mode or terminal attributes, or failure configuring the pty size on the freshly allocated tty.","commonSituations":"Exotic terminal types/env (TERM values) causing termios setup issues; race where the pty slave closes immediately; platform quirks in cgo termios calls; window-size ioctl failure.","solutions":["Retry the exec session — often transient if the pty closed unexpectedly","Check executor/logs for the underlying ioctl error and platform support","Try non-TTY exec as a workaround","Upgrade Nomad/executor for platform-specific termios fixes"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n    if strings.Contains(err.Error(), \"failed to set command tty\") {\n        // retry once, then fall back to non-tty exec\n        opts.Tty = false\n        err = run()\n    }\n}","preventionTips":["Keep executor and client versions in sync for termios fixes","Avoid unusual TERM environments for exec sessions","Fall back to non-TTY exec for automated tooling"],"tags":["tty","termios","exec","container","nomad"],"backgroundTag":"pty-configuration-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"}