Skip to content

Commit 8cee51e

Browse files
committed
fix(server): skip Windows cleanup for exited child processes
Refs: #2537
1 parent b1ec4b3 commit 8cee51e

3 files changed

Lines changed: 65 additions & 3 deletions

File tree

‎patches/@[email protected]‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
diff --git a/dist/NodeChildProcessSpawner.js b/dist/NodeChildProcessSpawner.js
2+
--- a/dist/NodeChildProcessSpawner.js
3+
+++ b/dist/NodeChildProcessSpawner.js
4+
@@ -44,9 +44,17 @@
5+
return false;
6+
}
7+
};
8+
-const taskkill = (childProcess, onExit = () => {}) => NodeChildProcess.execFile("taskkill", ["/pid", String(childProcess.pid), "/T", "/F"], {
9+
- windowsHide: true
10+
-}, onExit);
11+
+const taskkill = (childProcess, onExit = () => {}) => {
12+
+ // Once Node observes the leader's exit, taskkill /T cannot reclaim orphaned
13+
+ // descendants through its PID, which may be reused. Skip stale-PID cleanup.
14+
+ if (childProcess.exitCode !== null || childProcess.signalCode !== null) {
15+
+ onExit(null);
16+
+ return;
17+
+ }
18+
+ NodeChildProcess.execFile("taskkill", ["/pid", String(childProcess.pid), "/T", "/F"], {
19+
+ windowsHide: true
20+
+ }, onExit);
21+
+};
22+
const make = /*#__PURE__*/Effect.gen(function* () {
23+
const fs = yield* FileSystem.FileSystem;
24+
const path = yield* Path.Path;
25+
diff --git a/src/NodeChildProcessSpawner.ts b/src/NodeChildProcessSpawner.ts
26+
--- a/src/NodeChildProcessSpawner.ts
27+
+++ b/src/NodeChildProcessSpawner.ts
28+
@@ -19,7 +19,9 @@
29+
* `forceKillAfter`, the wait is limited to one second and never escalates.
30+
* With it, cleanup may take the configured duration plus a final one-second
31+
* wait after `SIGKILL`. Zombie descendants can consume either full bound. On
32+
- * Windows, `taskkill` terminates the tree and only the leader's exit is awaited.
33+
+ * Windows, `taskkill` terminates the tree while the leader is running and only
34+
+ * the leader's exit is awaited. Descendants that outlive the leader are not
35+
+ * reclaimed by PID-based cleanup.
36+
*
37+
* POSIX cleanup targets a numeric process-group ID. If the group disappears
38+
* and its ID is reused before cleanup, an unrelated group may be signalled.
39+
@@ -99,13 +101,20 @@
40+
const taskkill = (
41+
childProcess: NodeChildProcess.ChildProcess,
42+
onExit: (error: NodeChildProcess.ExecException | null) => void = () => {}
43+
-) =>
44+
+) => {
45+
+ // Once Node observes the leader's exit, taskkill /T cannot reclaim orphaned
46+
+ // descendants through its PID, which may be reused. Skip stale-PID cleanup.
47+
+ if (childProcess.exitCode !== null || childProcess.signalCode !== null) {
48+
+ onExit(null)
49+
+ return
50+
+ }
51+
NodeChildProcess.execFile(
52+
"taskkill",
53+
["/pid", String(childProcess.pid!), "/T", "/F"],
54+
{ windowsHide: true },
55+
onExit
56+
)
57+
+}
58+
59+
const make = Effect.gen(function*() {
60+
const fs = yield* FileSystem.FileSystem

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ patchedDependencies:
288288
289289
290290
291+
291292
292293
293294

0 commit comments

Comments
 (0)