From b218059a202646986576c19de67f56e0a79da881 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 17:24:30 +0300 Subject: [PATCH] voelin-gpui: the close grace sleeps inside the runtime `runtime.block_on(tokio::time::sleep(CLOSE_GRACE))` makes the Sleep before block_on enters the runtime, which panics ("there is no reactor running") on the GPUI thread; the foundation had it because no slice opened a session, so the grace never ran. The first end-to-end close against a server (the TS3 dev server, a connected window closed with Alt+F4) found it: exit status 101 after the engine had sent the close. The sleep is made in an async block now, as the Slint front end does, and a test calls the wait from a thread that is no runtime thread (it fails with the old form). Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-gpui/src/lib.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/voelin-gpui/src/lib.rs b/crates/voelin-gpui/src/lib.rs index 40a6d77..f3e45ea 100644 --- a/crates/voelin-gpui/src/lib.rs +++ b/crates/voelin-gpui/src/lib.rs @@ -172,6 +172,14 @@ fn open_main_window( Ok(()) } +/// Wait `grace` on `runtime`, so that the engine's tasks run (they send the +/// closes of the sessions) before the runtime drops them. The sleep is made +/// inside the runtime: a `Sleep` made outside it, as an argument of +/// `block_on`, panics ("there is no reactor running"). +fn give_the_engine_time(runtime: &tokio::runtime::Runtime, grace: Duration) { + runtime.block_on(async move { tokio::time::sleep(grace).await }); +} + /// Run the app on the current thread until its window closes. pub fn run() -> Result<()> { init_logging(); @@ -228,7 +236,7 @@ pub fn run() -> Result<()> { // on the servers until they time out. Any other way to end the app that // the slices add must call `AppState::shutdown` too. if closed_sessions.get() > 0 { - runtime.block_on(tokio::time::sleep(CLOSE_GRACE)); + give_the_engine_time(&runtime, CLOSE_GRACE); } runtime.shutdown_timeout(Duration::from_secs(2)); match failure.take() { @@ -236,3 +244,21 @@ pub fn run() -> Result<()> { None => Ok(()), } } + +#[cfg(test)] +mod tests { + use super::*; + + /// The grace after a close with open sessions is a wait on the engine's + /// runtime from the GPUI thread, which is no runtime thread: it must not + /// panic, and it must wait. (The first end-to-end close against a server, + /// the first slice that opens a session, found the panic.) + #[test] + fn the_close_grace_waits_on_the_runtime_from_a_thread_that_is_none() { + let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap(); + let started = std::time::Instant::now(); + give_the_engine_time(&runtime, Duration::from_millis(30)); + assert!(started.elapsed() >= Duration::from_millis(30)); + runtime.shutdown_timeout(Duration::from_secs(2)); + } +}