{"record":{"id":"781c3c9f304b2921","repo":"hashicorp/nomad","slug":"attempted-to-resize-a-non-tty-session","errorCode":null,"errorMessage":"attempted to resize a non-tty session","messagePattern":"attempted to resize a non-tty session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/shared/executor/pty_unix.go","lineNumber":30,"sourceCode":"\t\"os\"\n\t\"strings\"\n\t\"syscall\"\n\n\t\"github.com/creack/pty\"\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc sessionCmdAttr(tty *os.File) *syscall.SysProcAttr {\n\treturn &syscall.SysProcAttr{\n\t\tSetsid:  true,\n\t\tSetctty: true,\n\t}\n}\n\nfunc setTTYSize(w io.Writer, height, width int32) error {\n\tf, ok := w.(*os.File)\n\tif !ok {\n\t\treturn fmt.Errorf(\"attempted to resize a non-tty session\")\n\t}\n\n\treturn pty.Setsize(f, &pty.Winsize{\n\t\tRows: uint16(height),\n\t\tCols: uint16(width),\n\t})\n\n}\n\nfunc isUnixEIOErr(err error) bool {\n\tif err == nil {\n\t\treturn false\n\t}\n\n\treturn strings.Contains(err.Error(), unix.EIO.Error())\n}\n","sourceCodeStart":12,"sourceCodeEnd":47,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/shared/executor/pty_unix.go#L12-L47","documentation":"On Unix, setTTYSize resizes a terminal via pty.Setsize, which requires the writer to be the *os.File backing a real PTY. This error is returned when a resize request targets a session whose output writer is not a PTY file (i.e., the exec session is not a TTY).","triggerScenarios":"Calling TerminalResize on a non-TTY exec session (task exec started with tty=false), or passing a buffered/pipe writer instead of the PTY *os.File.","commonSituations":"Terminal UI (e.g. nomad monitor/exec clients) sending SIGWINCH-driven resize events for sessions allocated without a TTY; drivers that don't allocate PTYs on the given platform.","solutions":["Only request terminal resize for sessions created with tty=true","Check the session's Tty flag before calling resize and skip silently when false","Allocate the session with TTY enabled if interactive resize is required","Fix caller code to pass the original PTY *os.File, not a wrapper writer"],"exampleFix":"// before\nsetTTYSize(session.Output, h, w) // Output is a pipe\n// after\nif session.Tty {\n    setTTYSize(session.Output, h, w)\n}","handlingStrategy":"validation","validationCode":"if !session.Tty { skip resize }","typeGuard":"func isPTYFile(w io.Writer) (*os.File, bool) {\n    f, ok := w.(*os.File)\n    return f, ok\n}","tryCatchPattern":"if err := session.Resize(h, w); err != nil && strings.Contains(err.Error(), \"non-tty\") {\n    // ignore: session has no PTY\n}","preventionTips":["Only resize TTY-enabled sessions","Check the session's Tty flag before sending resize events","Handle SIGWINCH by skipping resize for non-interactive sessions"],"tags":["tty","pty","unix","resize"],"backgroundTag":"resize-non-tty-session","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"}