Skip to content

fix(win): don't close the pseudoconsole twice on a second kill() - #989

Open
shrmguy (leroyomey) wants to merge 1 commit into
microsoft:mainfrom
leroyomey:fix-double-kill
Open

shrmguy (leroyomey) wants to merge 1 commit into
microsoft:mainfrom
leroyomey:fix-double-kill

Conversation

@leroyomey

Copy link
Copy Markdown

Fixes #983.

PtyKill closes the pseudoconsole but leaves handle->hpc pointing at it, and the handle stays in ptyHandles until the exit watcher removes it. A second kill() in that gap closes the same pseudoconsole again, which with useConptyDll: true takes the process down with 0xC0000374.

PtyKill now sets hpc to null once it has closed it, and skips the close if it's already null. I added the same check to PtyResize and PtyClear, since they can run in the same gap and were passing the closed handle along.

The script from the issue crashed every time for me on Windows 11 (26200, Node 24) and survives with this change, with cmd.exe and powershell.exe. The new test takes down the mocha run without the fix. npm test passes.

My Build Tools install has no Spectre libraries, so I built locally with SpectreMitigation off. I didn't try the onExit timing variant from the issue, it needs a loaded machine. It goes through the same second close, so this should cover it.

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: a second kill() on the same pty closes the pseudo-console twice and crashes the process with 0xC0000374

1 participant