From bc39cd2806ca4d32fcebaef652c80803af568dd4 Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Mon, 2 Jun 2025 12:43:24 -0700 Subject: [PATCH] avoid assertion error --- src/bun.js/web_worker.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bun.js/web_worker.zig b/src/bun.js/web_worker.zig index 9cfbadd914..5236cd30d4 100644 --- a/src/bun.js/web_worker.zig +++ b/src/bun.js/web_worker.zig @@ -572,7 +572,18 @@ pub fn notifyNeedTermination(this: *WebWorker) callconv(.c) void { if (this.vm) |vm| { vm.eventLoop().wakeup(); - vm.jsc.notifyNeedTermination(); + + // for process.exit() called from JavaScript, we only need to set the flag + // and wake up the event loop. The event loop will check hasRequestedTerminate() + // and exit cleanly. Calling notifyNeedTermination() while holding the js lock + // causes assertion failures in jsc + if (!this.exit_called) { + // only call jsc traps for external terminate requests + // (e.g worker.terminate() from parent thread) + vm.jsc.notifyNeedTermination(); + } + // if exit_called is true we're in process.exit() context and should + // let the event loop handle termination naturally } // TODO(@190n) delete