From d56e63a91bff7f3bee5d6c6fd4570ffddd435f5f Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 27 Feb 2026 08:20:31 +0800 Subject: [PATCH] On Client.stop, terminate the isolate Shutdown on MacOS doesn't work properly. The process appears to shutdown, but will continue to run in the background. It can run infinitely if it's stuck in a JS loop. To help it along, Client.stop now force-terminates the isolate. I also don't think shutdown is working as intended on Linux, but the problem seems less serious there. On Linux, it appears to properly kill the process (which is the important thing), but I don't think it necessarily does a clean shutdown. --- src/Server.zig | 4 ++++ src/browser/js/Env.zig | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Server.zig b/src/Server.zig index 1b0c5099..bd990560 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -296,6 +296,10 @@ pub const Client = struct { } fn stop(self: *Client) void { + switch (self.mode) { + .http => {}, + .cdp => |*cdp| cdp.browser.env.terminate(), + } self.ws.shutdown(); } diff --git a/src/browser/js/Env.zig b/src/browser/js/Env.zig index 2f1b6b1e..1a86ffd5 100644 --- a/src/browser/js/Env.zig +++ b/src/browser/js/Env.zig @@ -470,6 +470,10 @@ pub fn dumpMemoryStats(self: *Env) void { , .{ stats.total_heap_size, stats.total_heap_size_executable, stats.total_physical_size, stats.total_available_size, stats.used_heap_size, stats.heap_size_limit, stats.malloced_memory, stats.external_memory, stats.peak_malloced_memory, stats.number_of_native_contexts, stats.number_of_detached_contexts, stats.total_global_handles_size, stats.used_global_handles_size, stats.does_zap_garbage }); } +pub fn terminate(self: *const Env) void { + v8.v8__Isolate__TerminateExecution(self.isolate.handle); +} + fn promiseRejectCallback(message_handle: v8.PromiseRejectMessage) callconv(.c) void { const promise_handle = v8.v8__PromiseRejectMessage__GetPromise(&message_handle).?; const v8_isolate = v8.v8__Object__GetIsolate(@ptrCast(promise_handle)).?;