From e63df747156c9db2cb74ae342e119a2a418371ea Mon Sep 17 00:00:00 2001 From: RustDesk <71636191+rustdesk@users.noreply.github.com> Date: Thu, 30 Jul 2026 12:01:05 +0800 Subject: [PATCH] fix(linux): make quit_cm actually quit the connection manager (#15718) quit_gui() ends the process on Windows (std::process::exit) and macOS (NSApp terminate), but on Linux it calls gtk_main_quit(), which has no effect in the Flutter connection manager: flutter/linux/main.cc runs g_application_run() (GtkApplication), so gtk_main() is never called and the assertion inside gtk_main_quit() just fails. quit_cm() is the only caller that relies on quit_gui() to end the process. The main window path in ipc.rs calls std::process::exit(-1) right after it, and the two remaining call sites are in the Sciter UI, which is not compiled for flutter builds. So a connection manager reaching quit_cm() on Linux kept running while no longer serving the `_cm` ipc endpoint, which also stops the server from reusing it, so the next connection spawns one more. NOTE: this is a fallback, not an explanation for the stale processes of #15698: a client merely disconnecting does not reach quit_cm(), the Flutter side closes the window instead. Co-authored-by: Claude Fable 5 --- src/ui_cm_interface.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index cab0d7f1c..b62f59c54 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -1686,6 +1686,19 @@ pub fn quit_cm() { // in case of std::process::exit not work log::info!("quit cm"); CLIENTS.write().unwrap().clear(); + // `quit_gui()` ends the process on Windows and macOS, but on Linux it calls + // `gtk_main_quit()`, which has no effect in the Flutter connection manager: + // `flutter/linux/main.cc` runs `g_application_run()` (GtkApplication), so + // `gtk_main()` is never called. Exit directly instead, otherwise this + // process keeps running while no longer serving the `_cm` ipc endpoint, so + // the server can't reuse it and spawns one more connection manager. + // + // NOTE: a client merely disconnecting does not come here, the Flutter side + // closes the window then, so this is a fallback rather than an explanation + // for the stale processes of #15698. + #[cfg(all(target_os = "linux", feature = "flutter"))] + std::process::exit(0); + #[cfg(not(all(target_os = "linux", feature = "flutter")))] crate::platform::quit_gui(); }