Skip to content

Commit 2875c7b

Browse files
committed
fix: wrap blocking_lock in block_in_place to prevent async runtime panic
The cookie helper functions use blocking_lock() which panics when called from within a tokio async runtime. This was causing the gateway to crash on startup when web tools tried to access the vault cookie jar. Wrapping in tokio::task::block_in_place() allows the blocking operation to safely execute within the multi-threaded runtime by temporarily leaving the async context.
1 parent 5816182 commit 2875c7b

File tree

1 file changed

+14
-7
lines changed
  • crates/rustyclaw-core/src/tools

1 file changed

+14
-7
lines changed

crates/rustyclaw-core/src/tools/web.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,20 +593,27 @@ fn exec_web_search_sync(args: &Value, _workspace_dir: &Path) -> Result<String, S
593593
}
594594

595595
// ── Cookie helpers (sync) ───────────────────────────────────────────────────
596+
//
597+
// These are called from blocking HTTP code but may run inside a tokio runtime.
598+
// We use `block_in_place` to safely allow blocking in the current thread.
596599

597600
fn get_cookie_header_sync(domain: &str, path: &str, is_secure: bool) -> Option<String> {
598601
let vault_ref = vault()?;
599-
let mut vault_guard = vault_ref.blocking_lock();
600-
vault_guard
601-
.cookie_header_for_request(domain, path, is_secure, true)
602-
.ok()
603-
.flatten()
602+
tokio::task::block_in_place(|| {
603+
let mut vault_guard = vault_ref.blocking_lock();
604+
vault_guard
605+
.cookie_header_for_request(domain, path, is_secure, true)
606+
.ok()
607+
.flatten()
608+
})
604609
}
605610

606611
fn store_response_cookies_sync(domain: &str, headers: &[String]) {
607612
if let Some(vault_ref) = vault() {
608-
let mut vault_guard = vault_ref.blocking_lock();
609-
let _ = vault_guard.store_cookies_from_response(domain, headers, true);
613+
tokio::task::block_in_place(|| {
614+
let mut vault_guard = vault_ref.blocking_lock();
615+
let _ = vault_guard.store_cookies_from_response(domain, headers, true);
616+
});
610617
}
611618
}
612619

0 commit comments

Comments
 (0)