Skip to content

Commit 0163489

Browse files
authored
fix(core): safe_block_on usage on async contexts, closes #3505 (#3513)
1 parent 944b124 commit 0163489

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changes/fix-safe-block-on.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes `Command::output` and `Command::status` deadlock when running on async commands.

core/tauri/src/async_runtime.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ where
285285
F: Future + Send + 'static,
286286
F::Output: Send + 'static,
287287
{
288-
if tokio::runtime::Handle::try_current().is_ok() {
288+
if let Ok(handle) = tokio::runtime::Handle::try_current() {
289289
let (tx, rx) = std::sync::mpsc::sync_channel(1);
290-
spawn(async move {
291-
tx.send(task.await).unwrap();
290+
let handle_ = handle.clone();
291+
handle.spawn_blocking(move || {
292+
tx.send(handle_.block_on(task)).unwrap();
292293
});
293294
rx.recv().unwrap()
294295
} else {

0 commit comments

Comments
 (0)