Skip to content

fix: surface CreateProcessW failures as 'exit' instead of uncaughtException on Windows#934

Open
codebytere-ant wants to merge 1 commit into
microsoft:mainfrom
codebytere-ant:fix/windows-connect-error-uncaught
Open

fix: surface CreateProcessW failures as 'exit' instead of uncaughtException on Windows#934
codebytere-ant wants to merge 1 commit into
microsoft:mainfrom
codebytere-ant:fix/windows-connect-error-uncaught

Conversation

@codebytere-ant

@codebytere-ant codebytere-ant commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Since connect() was deferred to _completePtyConnection() (#885), a failure from CreateProcessWERROR_FILE_NOT_FOUND, ERROR_ACCESS_DISABLED_BY_POLICY (1260) under AppLocker/WDAC, etc. — throws from inside the conout worker's onReady callback (or its 5s timeout fallback). Nothing is in a position to catch it: pty.spawn() has already returned, and the outSocket 'close' listener that drives 'exit' isn't attached until ready_datapipe, which never fires. The throw lands as a process-level uncaughtException, the pseudoconsole and worker thread leak, and the consumer's IPty sits with pid === 0 and no onExit.

Before #885 the same throw was synchronous inside the WindowsPtyAgent constructor and propagated out of pty.spawn(), so callers could try { spawn() } catch.

This adds an onError event on WindowsPtyAgent that WindowsTerminal subscribes to in its constructor (i.e., before any async work). On a connect() throw the agent releases the pseudoconsole, disposes the conout worker, destroys both sockets, sets exitCode to the GetLastError() value parsed from the native error string (or -1), and fires the event; WindowsTerminal routes it to 'exit' so the public onExit fires.

Test exercises the path by spawning an existing non-executable file (package.json) — it passes startProcess's existence check, then CreateProcessW fails inside connect() with ERROR_BAD_EXE_FORMAT.

cc @deepak1556

@deepak1556

Copy link
Copy Markdown
Contributor

Can you address the failing tests, thanks!

@deepak1556 deepak1556 added this to the 1.127.0 milestone Jun 26, 2026
@codebytere-ant codebytere-ant force-pushed the fix/windows-connect-error-uncaught branch from d5dde84 to 9a5828f Compare June 26, 2026 07:40
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.

2 participants