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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user