fix: address review feedback (星月)

1. trySendSync: wrap child.send in try/catch — IPC race between connected check and send
2. gracefulStop: same try/catch for shutdown send
3. Remove crashTimestamps reset on ready — crash window detection was being bypassed
This commit is contained in:
2026-04-30 13:41:31 +00:00
parent 4dffcb636b
commit e67ddc58d8
+11 -4
View File
@@ -187,7 +187,6 @@ export function createWorkerRuntime<K extends string>(
if (isReadyIpcMessage(msg)) {
if (slot.state === "starting") {
slot.state = "ready";
slot.crashTimestamps = [];
config.onReady(slot.key, msg);
resolveReadyWaiters(slot);
}
@@ -272,7 +271,11 @@ export function createWorkerRuntime<K extends string>(
slot.expectExit = true;
slot.state = "draining";
const child = slot.child;
child.send({ type: "shutdown" });
try {
child.send({ type: "shutdown" });
} catch {
// IPC channel may have closed between null-check and send
}
await waitForChildExit(child, config.shutdownTimeoutMs);
}
@@ -330,8 +333,12 @@ export function createWorkerRuntime<K extends string>(
if (child === null || !child.connected) {
return false;
}
child.send(msg as Serializable);
return true;
try {
child.send(msg as Serializable);
return true;
} catch {
return false;
}
},
start: async (key: K) => {