fix: surface CreateProcessW failures as 'exit' instead of uncaughtException on Windows#934
Open
codebytere-ant wants to merge 1 commit into
Open
Conversation
Contributor
|
Can you address the failing tests, thanks! |
…eption on Windows
d5dde84 to
9a5828f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since
connect()was deferred to_completePtyConnection()(#885), a failure fromCreateProcessW—ERROR_FILE_NOT_FOUND,ERROR_ACCESS_DISABLED_BY_POLICY(1260) under AppLocker/WDAC, etc. — throws from inside the conout worker'sonReadycallback (or its 5s timeout fallback). Nothing is in a position to catch it:pty.spawn()has already returned, and theoutSocket'close'listener that drives'exit'isn't attached untilready_datapipe, which never fires. The throw lands as a process-leveluncaughtException, the pseudoconsole and worker thread leak, and the consumer'sIPtysits withpid === 0and noonExit.Before #885 the same throw was synchronous inside the
WindowsPtyAgentconstructor and propagated out ofpty.spawn(), so callers couldtry { spawn() } catch.This adds an
onErrorevent onWindowsPtyAgentthatWindowsTerminalsubscribes to in its constructor (i.e., before any async work). On aconnect()throw the agent releases the pseudoconsole, disposes the conout worker, destroys both sockets, setsexitCodeto theGetLastError()value parsed from the native error string (or-1), and fires the event;WindowsTerminalroutes it to'exit'so the publiconExitfires.Test exercises the path by spawning an existing non-executable file (
package.json) — it passesstartProcess's existence check, thenCreateProcessWfails insideconnect()withERROR_BAD_EXE_FORMAT.cc @deepak1556