Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/jsc/VirtualMachine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use core::cell::Cell;
use core::ffi::{c_char, c_int, c_void};
use core::ptr::NonNull;
use core::sync::atomic::{AtomicBool, Ordering};

use bun_bundler::Transpiler;
use bun_io as Async;
Expand Down Expand Up @@ -207,7 +208,7 @@ pub struct VirtualMachine {
pub hide_bun_stackframes: bool,

pub is_printing_plugin: bool,
pub is_shutting_down: bool,
pub is_shutting_down: AtomicBool,
pub plugin_runner: Option<crate::plugin_runner::PluginRunner>,
pub is_main_thread: bool,
pub exit_handler: ExitHandler,
Expand Down Expand Up @@ -981,13 +982,13 @@ impl VirtualMachine {
}

pub fn is_shutting_down(&self) -> bool {
self.is_shutting_down
self.is_shutting_down.load(Ordering::Acquire)
}

/// Port of `VirtualMachine.scriptExecutionStatus` (VirtualMachine.zig:885).
/// Exported to C++ as `Bun__VM__scriptExecutionStatus` via virtual_machine_exports.rs.
pub fn script_execution_status(&self) -> crate::ScriptExecutionStatus {
if self.is_shutting_down {
if self.is_shutting_down.load(Ordering::Acquire) {
return crate::ScriptExecutionStatus::Stopped;
}

Expand Down Expand Up @@ -1485,7 +1486,7 @@ impl VirtualMachine {
}

ExitHandler::dispatch_on_exit(self);
self.is_shutting_down = true;
self.is_shutting_down.store(true, Ordering::Release);

// Make sure we run new cleanup hooks introduced by running cleanup
// hooks.
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ impl WebWorker {
// clear it so process.on('exit') handlers can run. teardownJSCVM
// re-sets it for the JSC VM teardown.
vm.jsc_vm().clear_has_termination_request();
vm.is_shutting_down = true;
vm.is_shutting_down.store(true, Ordering::Release);
vm.on_exit();
if let Some(hooks) = runtime_hooks() {
(hooks.cron_clear_all_teardown)(vm);
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/cli/test_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::cli::test::changed_files_filter as ChangedFilesFilter;
use crate::cli::test::parallel_runner as ParallelRunner;
use crate::cli::test::scanner::{self, Scanner};
use bun_collections::{ArrayHashMap, BoundedArray, StringHashMap};
use core::sync::atomic::Ordering;
use bun_core::{self as bun, Global, Output, env_var, fmt as bun_fmt};
use bun_core::{err_generic, pretty_error, pretty_errorln};
use bun_dotenv as DotEnv;
Expand Down Expand Up @@ -2398,7 +2399,7 @@ impl TestCommand {
);
}
vm.exit_handler.exit_code = 1;
vm.is_shutting_down = true;
vm.is_shutting_down.store(true, Ordering::Release);
let vm_ptr: *mut VirtualMachine = vm;
vm.run_with_api_lock(|| unsafe { (*vm_ptr).global_exit() });
}
Expand Down Expand Up @@ -2493,7 +2494,7 @@ impl TestCommand {
);
}
vm.exit_handler.exit_code = 1;
vm.is_shutting_down = true;
vm.is_shutting_down.store(true, Ordering::Release);
let vm_ptr: *mut VirtualMachine = vm;
vm.run_with_api_lock(|| unsafe { (*vm_ptr).global_exit() });
}
Expand Down Expand Up @@ -3025,7 +3026,7 @@ impl TestCommand {
} else if reporter.jest.unhandled_errors_between_tests > 0 {
vm.exit_handler.exit_code = 1;
}
vm.is_shutting_down = true;
vm.is_shutting_down.store(true, Ordering::Release);
{
let vm_ptr: *mut VirtualMachine = vm;
vm.run_with_api_lock(|| unsafe { (*vm_ptr).global_exit() });
Expand Down Expand Up @@ -3256,7 +3257,7 @@ impl TestCommand {
reporter.write_junit_report_if_needed();

vm.exit_handler.exit_code = 1;
vm.is_shutting_down = true;
vm.is_shutting_down.store(true, Ordering::Release);
// SAFETY: global_exit diverges; raw-ptr reborrow mirrors Zig
// runWithAPILock(*VM, vm, globalExit).
let vm_ptr = std::ptr::from_mut::<VirtualMachine>(vm);
Expand Down