From b1062207435dcc67e2cfd6b0c90cc796b67fe30d Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Thu, 18 Sep 2025 01:35:22 +0400 Subject: [PATCH] main thread in browser can't execute parking - so we use parking lot in spin-lock style for that target --- core/storage/wal.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 3edf3f6d5..d6b111172 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -1639,11 +1639,41 @@ impl WalFile { } fn get_shared_mut(&self) -> parking_lot::RwLockWriteGuard<'_, WalFileShared> { - self.shared.write() + // WASM in browser main thread doesn't have a way to "park" a thread + // so, we spin way here instead of calling blocking lock + #[cfg(target_family = "wasm")] + { + loop { + let Some(lock) = self.shared.try_write() else { + std::hint::spin_loop(); + continue; + }; + return lock; + } + } + #[cfg(not(target_family = "wasm"))] + { + self.shared.write() + } } fn get_shared(&self) -> parking_lot::RwLockReadGuard<'_, WalFileShared> { - self.shared.read() + // WASM in browser main thread doesn't have a way to "park" a thread + // so, we spin way here instead of calling blocking lock + #[cfg(target_family = "wasm")] + { + loop { + let Some(lock) = self.shared.try_read() else { + std::hint::spin_loop(); + continue; + }; + return lock; + } + } + #[cfg(not(target_family = "wasm"))] + { + self.shared.read() + } } fn complete_append_frame(&mut self, page_id: u64, frame_id: u64, checksums: (u32, u32)) {