Skip to content

Commit bd4bfb5

Browse files
committed
fix: prevent panic when set_scripts called from async runtime
Use block_in_place to wrap blocking_write() call on tokio::sync::RwLock. This prevents panic when set_scripts RPC is called from HTTP worker threads running inside the tokio runtime.
1 parent 075d095 commit bd4bfb5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

light-client-lib/src/service/impls.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,11 @@ impl LightClientChainService {
770770
scripts: Vec<crate::service::ScriptStatus>,
771771
command: Option<crate::service::SetScriptsCommand>,
772772
) {
773-
// Both platforms use blocking_write since matched_blocks() returns tokio::sync::RwLock
774-
let mut matched_blocks = self.swc.matched_blocks().blocking_write();
773+
// Use block_in_place to allow blocking operations within an async runtime context.
774+
// This is necessary because set_scripts may be called from RPC handlers running
775+
// inside a tokio runtime, where blocking_write() would panic.
776+
let mut matched_blocks =
777+
tokio::task::block_in_place(|| self.swc.matched_blocks().blocking_write());
775778

776779
let scripts = scripts.into_iter().map(Into::into).collect();
777780
self.swc

0 commit comments

Comments
 (0)