0003: Force-exit instead of graceful shutdown
Status: Accepted Date: Not recorded in the sourcesContext
Graceful Rust and libc shutdown deadlocks in this app. The code (src-tauri/src/shutdown.rs) records these causes:
- ONNX Runtime atexit handlers can deadlock during
dlclose()of provider libraries (onnxruntime#21207, unresolved as of 2026-04). webkit2gtkcan block on GTK main-loop teardown when a window was never fully realised.tauri-plugin-updatermay still hold areqwestrequest when the process tries to join the tokio runtime.process::exitis not thread-safe with C atexit handlers (rust-lang/rust#126600).
libc::_exit goes through the C runtime, which still runs DLL_PROCESS_DETACH for every loaded DLL. ORT, DirectML and audio drivers can hang in their detach handlers, leaving the process alive after “Quit”.
Decision
Every exit path goes through one function,shutdown::force_exit(code). It does a small amount of best-effort cleanup and then ends the process without running destructors:
- On Linux and macOS it calls
libc::_exit, a direct exit syscall that skips atexit handlers, C++ static destructors and Rust drops. - On Windows it calls
TerminateProcesson the current process, which skips all DLL teardown.
Consequences
- Cleanup that matters must be done explicitly inside
force_exit, because drop order is bypassed. Today that is: unregistering global shortcuts (otherwise a second launch can fail with “HotKey already registered”), removing the single-instance lock file, removing the IPC token and state files, and on macOS reverting the dictation-key remap. - Stdio buffers may lose their tail. Logging is line buffered, so the last log line before exit is still observable.
- New code that needs shutdown work must hook into
force_exit; relying onDropor on Tauri’s exit events will not run. - Do not replace this with
std::process::exit,app.exitorRunEvent::Exitwithout re-testing quit on every platform.