Skip to content

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

Open
euxaristia wants to merge 2 commits intomicrosoft:mainfrom
euxaristia:main
Open

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

Conversation

@euxaristia
Copy link

@euxaristia euxaristia commented Mar 13, 2026

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
Author

@euxaristia please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

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