hashicorp/nomad · error
attempted to resize a non-tty session
Error message
attempted to resize a non-tty session
What it means
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).
Source
Thrown at drivers/shared/executor/pty_unix.go:30
"os"
"strings"
"syscall"
"github.com/creack/pty"
"golang.org/x/sys/unix"
)
func sessionCmdAttr(tty *os.File) *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setsid: true,
Setctty: true,
}
}
func setTTYSize(w io.Writer, height, width int32) error {
f, ok := w.(*os.File)
if !ok {
return fmt.Errorf("attempted to resize a non-tty session")
}
return pty.Setsize(f, &pty.Winsize{
Rows: uint16(height),
Cols: uint16(width),
})
}
func isUnixEIOErr(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), unix.EIO.Error())
}
View on GitHub (pinned to 482b49bf1a)
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
Example fix
// before
setTTYSize(session.Output, h, w) // Output is a pipe
// after
if session.Tty {
setTTYSize(session.Output, h, w)
} Defensive patterns
Strategy: validation
Validate before calling
if !session.Tty { skip resize } Type guard
func isPTYFile(w io.Writer) (*os.File, bool) {
f, ok := w.(*os.File)
return f, ok
} Try / catch
if err := session.Resize(h, w); err != nil && strings.Contains(err.Error(), "non-tty") {
// ignore: session has no PTY
} Prevention
- Only resize TTY-enabled sessions
- Check the session's Tty flag before sending resize events
- Handle SIGWINCH by skipping resize for non-interactive sessions
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to open a tty: %v
- failed to get pty: %v
- failed to resize tty: %v
- not a terminal
- error creating fifo: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/781c3c9f304b2921.
Report an issue: GitHub.