From 55eb71982d3a7100024f51784c60137dc83c1256 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Fri, 3 Apr 2026 23:00:59 +0000 Subject: [PATCH] fix(js): use SeqCst ordering for cancellation flag to prevent race condition Closes #992 --- crates/bashkit-js/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bashkit-js/src/lib.rs b/crates/bashkit-js/src/lib.rs index 6add996b..6eae03de 100644 --- a/crates/bashkit-js/src/lib.rs +++ b/crates/bashkit-js/src/lib.rs @@ -273,7 +273,7 @@ impl Bash { /// Execute bash commands synchronously. #[napi] pub fn execute_sync(&self, commands: String) -> napi::Result { - self.state.cancelled.store(false, Ordering::Relaxed); + self.state.cancelled.store(false, Ordering::SeqCst); block_on_with(&self.state, |s| async move { let mut bash = s.inner.lock().await; match bash.exec(&commands).await { @@ -342,7 +342,7 @@ impl Bash { /// command boundary. #[napi] pub fn cancel(&self) { - self.state.cancelled.store(true, Ordering::Relaxed); + self.state.cancelled.store(true, Ordering::SeqCst); } /// Reset interpreter to fresh state, preserving configuration. @@ -604,7 +604,7 @@ impl BashTool { /// Execute bash commands synchronously. #[napi] pub fn execute_sync(&self, commands: String) -> napi::Result { - self.state.cancelled.store(false, Ordering::Relaxed); + self.state.cancelled.store(false, Ordering::SeqCst); block_on_with(&self.state, |s| async move { let mut bash = s.inner.lock().await; match bash.exec(&commands).await { @@ -670,7 +670,7 @@ impl BashTool { /// Cancel the currently running execution. #[napi] pub fn cancel(&self) { - self.state.cancelled.store(true, Ordering::Relaxed); + self.state.cancelled.store(true, Ordering::SeqCst); } /// Reset interpreter to fresh state, preserving configuration.