Skip to content

Commit 75daa52

Browse files
committed
fix(node): ensure worker backend stops cleanly on Bun
1 parent eed8db3 commit 75daa52

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/node/src/worker/engineWorker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
*/
3636
const PERF_ENABLED = (process.env as Readonly<{ REZI_PERF?: string }>).REZI_PERF === "1";
3737
const ZR_ERR_LIMIT = -3;
38+
const IS_BUN_RUNTIME = typeof (globalThis as { Bun?: unknown }).Bun !== "undefined";
3839
type PerfSample = { phase: string; durationMs: number };
3940
const perfSamples: PerfSample[] = [];
4041
const PERF_MAX_SAMPLES = 1024;
@@ -617,6 +618,13 @@ function shutdownNow(): void {
617618

618619
// Let worker thread exit naturally once handles are cleared.
619620
if (parentPort !== null) parentPort.close();
621+
// Bun worker_threads can keep the worker alive after parentPort.close().
622+
// Force a clean worker exit after sending shutdownComplete.
623+
if (IS_BUN_RUNTIME) {
624+
setImmediate(() => {
625+
process.exit(0);
626+
});
627+
}
620628
}
621629

622630
function tick(): void {

0 commit comments

Comments
 (0)