History

Fix workerd dispose reaping and declare effect peer dependency

Rhys Sullivan committed 4 months ago

Commit 02cc5e11 parent 21afc264 files · +14 −3Browse files

Unified · Split

4 files
  1. bun.lock +3 −0
  2. packages/kernel/runtime-workerd-subprocess/src/index.test.ts +5 −2
  3. packages/kernel/runtime-workerd-subprocess/src/index.ts +3 −1
  4. packages/plugins/apps/package.json +3 −0
bun.lock+3−0
@@ -808,6 +808,9 @@ · 807 unmodified lines
808808 "tsup": "catalog:",
809809 "vitest": "catalog:",
810810 },
811+ "peerDependencies": {
812+ "effect": "catalog:",
813+ },
811814 },
812815 "packages/plugins/desktop-settings": {
813816 "name": "@executor-js/plugin-desktop-settings",
packages/kernel/runtime-workerd-subprocess/src/index.test.ts+5−2
@@ -93,9 +93,12 @@ const pidIsGone = (pid: number): boolean => { · 92 unmodified lines
9393 };
9494
9595 const waitUntilGone = async (pid: number): Promise<boolean> => {
96− for (let index = 0; index < 100; index += 1) {
96+ // kill(pid, 0) still succeeds for an exited-but-unreaped child, so poll on a
97+ // real timer long enough for Node to reap it after the exit event.
98+ const deadline = Date.now() + 5_000;
99+ while (Date.now() < deadline) {
97100 if (pidIsGone(pid)) return true;
98− await new Promise((resolve) => setImmediate(resolve));
101+ await new Promise((resolve) => setTimeout(resolve, 10));
99102 }
100103 return pidIsGone(pid);
101104 };
packages/kernel/runtime-workerd-subprocess/src/index.ts+3−1
@@ -363,9 +363,11 @@ export const createWorkerdModuleRunner = ( · 362 unmodified lines
363363 const state = processState;
364364 processState = undefined;
365365 if (!state) return;
366− if (kill && !state.proc.killed) {
366+ if (kill && state.proc.exitCode === null && state.proc.signalCode === null) {
367367 // workerd serve ignores SIGTERM in this version. SIGKILL is the verified immediate shutdown path.
368+ const exited = new Promise<void>((resolve) => state.proc.once("exit", () => resolve()));
368369 state.proc.kill("SIGKILL");
370+ await exited;
369371 }
370372 await closeServer(state.hostServer).catch(() => undefined);
371373 await rm(state.tmp, { recursive: true, force: true }).catch(() => undefined);
packages/plugins/apps/package.json+3−0
@@ -45,5 +45,8 @@ · 44 unmodified lines
4545 "effect": "catalog:",
4646 "tsup": "catalog:",
4747 "vitest": "catalog:"
48+ },
49+ "peerDependencies": {
50+ "effect": "catalog:"
4851 }
4952 }