Repository navigation
fix(windows): keep Orca's std handles out of every spawned child - #35678
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] The PR appears safe to merge; the remaining finding affects warning accuracy, not whether handles are cleared. Findings
SummaryThis PR stops Windows children from accidentally keeping Orca's standard handles open.
Reviews (3) · Last reviewed commit: "test(windows): say why the std-handle te..." · Reviewed by Greptile |
| if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0)) { | ||
| auto failure = Napi::Object::New(env); | ||
| failure.Set("stream", stream.name); | ||
| failure.Set("code", static_cast<double>(GetLastError())); |
There was a problem hiding this comment.
Windows error can be overwritten
After SetHandleInformation fails, this code creates a JavaScript object and sets a field before reading GetLastError(). Those calls can overwrite the thread's last error, so startup may log the wrong code and hide why the handle stayed inheritable. Save GetLastError() immediately after the failed call, then use that saved value.
| if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0)) { | |
| auto failure = Napi::Object::New(env); | |
| failure.Set("stream", stream.name); | |
| failure.Set("code", static_cast<double>(GetLastError())); | |
| if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0)) { | |
| const DWORD code = GetLastError(); | |
| auto failure = Napi::Object::New(env); | |
| failure.Set("stream", stream.name); | |
| failure.Set("code", static_cast<double>(code)); |
4b3e875 to
bcf8cf5
Compare
libuv spawns with bInheritHandles=TRUE, so an inheritable std handle reached long-lived children such as the WSL holder and the daemon and held a launcher's pipe open after Orca exited. Clear HANDLE_FLAG_INHERIT on the std handles at the top of main startup; stdio 'inherit' still works because libuv hands the child its own inheritable duplicate.
…heritable Plain Node clears its std handles' inherit flag at startup, so a Node child never reproduced the leak. Electron main opts out of that, which is why Orca leaks and why the control arm now runs Electron; a plain-Node arm pins the difference.
bcf8cf5 to
f7f9be6
Compare
ELI5
When Orca starts a helper program on Windows, Windows hands that helper copies of some of Orca's own connections. Orca's standard input, output and error were among them. A helper that runs for a long time (the program that keeps a WSL distro awake, or the terminal daemon) then keeps those connections open after Orca exits. Whatever launched Orca (a script, a test runner, an installer) keeps waiting for output that will never come. This change tells Windows, once and at the top of startup, not to hand those three connections to any helper.
What Changed
stdio: 'inherit') still writes to it, because Node gives that child its own inheritable copy.Mechanism:
stdio: 'ignore'only affects which handles the child uses as its own standard streams. It does not stop other inheritable handles from being copied.clearStdHandleInheritance()innative/windows-security, clears the inherit flag on the three standard handles. It skips handles that are absent or invalid. It never throws: it returns any handle Windows refused, with the error code.src/main/startup/windows-std-handle-inheritance.tscalls it as the first statement insrc/main/index.ts, before the uninstall preflights and anything else that can spawn. Every failure, including a missing or stale addon, is logged and startup continues. It does nothing off Windows.ensure-native-runtime.mjs(install and CI check-only) andrebuild-native-deps.mjs(the Electron probe) now call the new export. A.nodebuilt from older source still loads but lacks the export, so the probe fails and triggers a rebuild instead of passing. The CI native-build cache already keys onaddon.cc, so x64 and arm64 release builds compile the new source.Why
Linked Issue
N/A (maintainer change; part of the WSL host idle-release work).
Visual Proof
N/A. There is no UI change: this only affects which handles Windows copies into child processes.
Testing
src/main/startup/windows-std-handle-inheritance.test.tsunit-tests the wiring with a mocked addon:src/main/startup/windows-std-handle-inheritance.win32.test.tsruns on the Windows CI lane (registered inpr-package-test-paths.mjs) against the real addon, with an Electron main process as the child. That is Orca's real shape: Electron opts out of the std-handle protection that plain Node applies to itself at startup.stdio: 'inherit'whose output must still arrive, and leaves a detachedstdio: 'ignore'holder behind.ORCA_BACKGROUND_LAUNCH=1, andELECTRON_RUN_AS_NODEremoved for the Electron child and set only for its grandchildren.Local (macOS):
pnpm run typecheck:ci, the touched tests andpnpm run check:code-quality:changedpass. The native code compiles and runs only on the Windows CI lane.The wrapper-hang check on a real Windows device is still pending.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Reviewers: fix-reviewer, e9-reviewer (touches every spawn).
Agent skill upstream boundary
Notes
Flag-off / User-risk: This is not behind a flag; it runs on every Windows launch. If the addon is missing or Windows refuses a handle, Orca logs a warning and behaves exactly as before. Remaining risk: a child that relied on implicitly receiving Orca's standard handles without being given them explicitly would lose them. Node's
stdio: 'inherit'and'pipe'both pass handles explicitly and are unaffected. Orca's main process is a GUI app whose standard handles are usually absent unless a launcher redirected them, and that redirected case is exactly the one this fixes.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)