fix: swallow resize() errors after PTY exit on Windows and Unix by euxaristia · Pull Request #901 · microsoft/node-pty · GitHub
Skip to content

fix: swallow resize() errors after PTY exit on Windows and Unix#901

Open
euxaristia wants to merge 2 commits into
microsoft:mainfrom
euxaristia:main
Open

fix: swallow resize() errors after PTY exit on Windows and Unix#901
euxaristia wants to merge 2 commits into
microsoft:mainfrom
euxaristia:main

Conversation

@euxaristia

@euxaristia euxaristia commented Mar 13, 2026

Copy link
Copy Markdown

Summary

  • Silently ignore resize() calls after the PTY process has already exited instead of throwing 'Cannot resize a pty that has already exited' (Windows)
  • Catch EBADF errors on resize() when the PTY file descriptor is already closed and silently return instead of crashing (Unix)
  • Prevents crashes on both platforms when a resize is triggered after process exit (e.g. during terminal cleanup)

Fixes #827

Details

Windows: The native conpty _exitCode guard previously threw an error, which could crash the host process if the caller didn't wrap resize() in a try/catch. This is a race condition that's more likely to surface on Node.js v22 due to timing changes in its stream/event loop internals.

Unix: pty.resize() throws 'ioctl(2) failed, EBADF' when the PTY file descriptor has already been closed before a resize event fires. The fix catches EBADF by both error code and message and silently returns.

Test plan

Silently ignore resize calls after the PTY process has exited instead
of throwing 'Cannot resize a pty that has already exited'. This prevents
crashes on Windows with Node.js v22 when a resize is attempted after
the process has exited.

Fixes microsoft#827
pty.resize() throws an error with message 'ioctl(2) failed, EBADF' when
the PTY file descriptor has already been closed (e.g. the process exited
and the fd was destroyed before a resize event fired). Catch EBADF by
both error code and message and silently return instead of crashing.
@euxaristia euxaristia changed the title fix: swallow resize() error when conpty has already exited fix: swallow resize() errors after PTY exit on Windows and Unix Mar 13, 2026
@euxaristia

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows crash on Node.js v22 – "Cannot resize a pty that has already exited"

1 participant