Repository navigation
Relocate node-pty ConPTY runtime outside the Windows install dir (fixes update-time terminal loss) - #7420
Closed
Jinwoo-H wants to merge 1 commit into
Closed
Relocate node-pty ConPTY runtime outside the Windows install dir (fixes update-time terminal loss)#7420Jinwoo-H wants to merge 1 commit into
Jinwoo-H wants to merge 1 commit into
Conversation
Root cause of update-time terminal loss (verified with a reproduction harness running the installer sweep commands verbatim): the NSIS update installer force-closes every process whose image path is under the install directory. Since #6968 started bundling conpty.dll and OpenConsole.exe under resources/, every live terminal's console host - and with 2+ matches the daemon too - is killed mid-update. Before #6968 the daemon was the only install-dir process and survived only by luck: the sweep's find step does (...).Count -gt 0, and in Windows PowerShell 5.1 a single-instance CIM result has null Count, so one match reads as "nothing running". Fix: copy the node-pty native runtime (conpty binding + conpty.dll + OpenConsole.exe + winpty) to userData/node-pty-runtime/<version>/ at startup and point the node-pty loader at it via ORCA_NODE_PTY_NATIVE_DIR (loader override added to the existing node-pty patch; falls through to the stock search paths on any failure). The daemon inherits the env var, so console hosts for both main- and daemon-owned PTYs run outside the installer kill zone. Stale version dirs are removed only when a rename probe proves nothing inside is still running. Verified end-to-end against the verbatim sweep: with the relocated runtime, OpenConsole spawns from userData, the sweep finds nothing to kill, and daemon + shell + console host all survive.
Contributor
Author
Reproduction harness evidence (installer sweep commands run verbatim against disposable topologies)Topology legs (sweep-repro.mjs)Single-match .Count blind spot (Windows PowerShell 5.1)Post-fix end-to-end (fix-verify.mjs: patched loader + relocated runtime + verbatim sweep) |
Contributor
Author
|
Superseded by #7421 targeting main (same commit cherry-picked; the fix is general, not perf-specific). orca-performance picks it up on the next main sync before the RC cut. |
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.
Summary
Windows terminal sessions die on every app update since June 30 because the NSIS update installer force-closes every process running from the install directory — and #6968 moved the ConPTY console hosts into it. This PR relocates node-pty's native runtime (
conpty.node,conpty.dll,OpenConsole.exe, winpty binaries) touserData/node-pty-runtime/<version>/, taking terminal infrastructure out of the installer's kill zone. Verified end-to-end against the installer's verbatim kill commands.Root cause (reproduction-harness verified, not inferred)
electron-builder's NSIS template (
allowOnlyOneInstallerInstance.nsh, unchanged in this repo since the initial commit) runsCHECK_APP_RUNNINGduring every update install:Three facts, each demonstrated by running these commands verbatim against disposable process topologies (harness output in the PR comments):
CimInstancewhose.Countis$null, so-gt 0is false and the installer concludes "nothing running" and kills nothing. Pre-Fix Windows bundled ConPTY packaging #6968, terminals used the System32 console host, so the detached daemon was the only install-dir process → single match → spared on every update. Same-process daemon survival across updates was real — and an accident.OpenConsole.exeinstances now underresources/, there are 2+ matches,.Countworks, and the sweep kills the daemon and every console host mid-install. Killing a console host kills its attached shell (reproduced; matches theGetConsoleScreenBufferInfoconsole-loss crashes Windows Error Reporting captured during the July 4 and July 5 update windows on the incident machine — and at no June update).OpenConsole.exespawns from userData, FIND reports nothing (the daemon is again the sole install-dir process, back under the single-match umbrella), and daemon + shell + console host all survive the sweep.This also corrects the earlier working theory: the update-relaunch wedge-kill path fixed in #7340 is real and reproducible, but the installer sweep — not that path — is what killed sessions in the July incidents.
Fix
config/patches/[email protected]):loadNativeModulehonorsORCA_NODE_PTY_NATIVE_DIRbefore its stock search paths, falling through on any failure. The native side already resolvesconpty.dll(and spawnsOpenConsole.exe) fromconpty/beside the loaded binding, so relocating the binding relocates the console hosts.src/main/pty/node-pty-runtime-relocation.ts: at startup (win32 + packaged only), copy the binding dir (rebuiltbuild/Release, fallback platform prebuilds;.pdbexcluded) touserData/node-pty-runtime/<appVersion>/and set the env var. Crash-safe via a completion marker (partial copies redone). The forked daemon inherits the env, covering daemon-owned PTYs.Verification
ORCA_NODE_PTY_NATIVE_DIRpointing at a relocated runtime; real ConPTY session with a livepowershell.exe.OpenConsole.exeverified running from the relocated dir; the verbatim installer FIND/KILL sequence found nothing and daemon, shell, and console host all survived. Control legs: pre-fix (July) topology → all killed; pre-Fix Windows bundled ConPTY packaging #6968 (June) topology → all spared via the single-match blind spot.node-pty-runtime-relocation.test.ts): source-dir resolution order, tree copy without symbols, marker idempotency, interrupted-copy recovery, stale-version cleanup keeping the current version, fail-open on missing source — plus a win32 integration test loading the real conpty binding through the patched loader from a relocated dir.terminal-cwd-realpath.test.ts, untouched by this change and identical on the base branch).Follow-ups (not in this PR)
INSTDIR\Orca.exe; today it survives via the single-match blind spot. Moving its image out of the install dir makes survival principled instead of accidental (and is the fix that remains correct if electron-builder ever repairs the.Countcheck upstream)..Countbug means the sweep silently skips exactly-one-process cases for every Electron app; conversely apps with detached helpers under the install dir lose them whenever there are 2+.