-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Describe the bug
I'm getting this output indicating a busy loop:
Ran Tauri iteration at 4.7094867s
Ran Tauri iteration at 4.7097679s
Ran Tauri iteration at 4.7099947s
Ran Tauri iteration at 4.710248s
Ran Tauri iteration at 4.7104644s
Ran Tauri iteration at 4.7106774s
Ran Tauri iteration at 4.7108921s
Ran Tauri iteration at 4.7111063s
Ran Tauri iteration at 4.7113324s
Ran Tauri iteration at 4.7115689s
Ran Tauri iteration at 4.7118283s
Ran Tauri iteration at 4.7120621s
Ran Tauri iteration at 4.7122877s
Ran Tauri iteration at 4.712554s
Ran Tauri iteration at 4.8543264s
Reproduction
https://github.com/ReactorScram/tauri_repro
Run cargo tauri dev or cd src-tauri; cargo run. stdout will be filled with constant print statements.
fn main() {
let mut app = tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.build(tauri::generate_context!())
.expect("should be able to build the Tauri app");
let start_time = std::time::Instant::now();
loop {
let iteration = app.run_iteration();
println!("Ran Tauri iteration at {:?}", start_time.elapsed());
if iteration.window_count == 0 {
break;
}
}
}Expected behavior
I expected from #5532 that run_iteration would block until the main event loop receives an event, then process it, then return.
Instead it doesn't seem to block, at least on Windows.
This is part of a larger yak shave for me. I'm trying to join a worker thread after Tauri exits, but all these methods have failed:
app.exitdoesn't triggerRunEvent::Exit(intentional behavior per Does `app.exit()` not trigger `RunEvent::Exit` event? #4662), so I can't clean up in thererun_iterationbusy loops- No way to inject my own
RunEventinto the main loop to wake uprunand check whether we need to clean up - No known way to just stop the Tauri event loop and let things
Dropnaturally, per [bug] Some resources are not dropped when tauri app is closed #7358 - No way to register something like
on_exitwithBuilderhttps://docs.rs/tauri/latest/tauri/struct.Builder.html
My fallback plan is to write my own cleanup function and call that, and have it call app.exit at the end. It'll work, but it'll require some comments explaining it.
Full tauri info output
(I'm on Windows 11 Home. I'm not sure why it says Windows 10.)
WARNING: no lock files found, defaulting to npm
[✔] Environment
- OS: Windows 10.0.22621 X64
✔ WebView2: 120.0.2210.133
✔ MSVC:
- Visual Studio Build Tools 2019
- Visual Studio Community 2022
✔ rustc: 1.75.0 (82e1608df 2023-12-21)
✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
- node: 20.10.0
- npm: 10.2.3
[-] Packages
- tauri [RUST]: 1.5.4
- tauri-build [RUST]: 1.5.1
- wry [RUST]: 0.24.7
- tao [RUST]: 0.16.6
- tauri-cli [RUST]: 1.5.6
- @tauri-apps/api : not installed!
- @tauri-apps/cli [NPM]: 1.5.6 (outdated, latest: 1.5.9)
[-] App
- build-type: bundle
- CSP: unset
- distDir: ../src
- devPath: ../src
Stack trace
N/A
Additional context
If this is a platform limitation, like maybe it's just impossible to gracefully stop a GUI event loop on Windows, I would understand.
But if it's not... can I just have an app.stop that stops the event loop, so everything can Drop?
Seems to be a tao thing, see later comment
