From dfbeb23f25b4ef2c88f838664a7648028db14704 Mon Sep 17 00:00:00 2001 From: K Panuragh Date: Fri, 13 Nov 2026 23:17:58 +0530 Subject: [PATCH] ui: Don't abort when the request ended before a UI event was sent The GTK view model unwrapped every send to the request's event loop. If the caller disconnected right after CreateSession, the loop had already ended when the UI sent Initiated, and credentialsd-ui aborted with SendError. Log a warning instead; the UI closes with the request anyway. --- CHANGELOG.md | 1 + credentialsd-ui/src/gui/view_model/gtk/mod.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76488bcd..77987506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - daemon: Build the list of devices offered to the user from libwebauthn's `available_transports()`, the same source discovery uses (#32) - ui: Pass the caller's activation token to the compositor when showing the dialog, so it can take focus when the requesting window is in the background (#152) +- ui: Don't crash when a request ends while the UI is still sending it events, e.g. because the caller disconnected right after starting it # 0.4.0 [2026-11-05] diff --git a/credentialsd-ui/src/gui/view_model/gtk/mod.rs b/credentialsd-ui/src/gui/view_model/gtk/mod.rs index f2b7d305..b279d90f 100644 --- a/credentialsd-ui/src/gui/view_model/gtk/mod.rs +++ b/credentialsd-ui/src/gui/view_model/gtk/mod.rs @@ -14,7 +14,7 @@ use gtk::glib::{self, Bytes}; use gtk::prelude::*; use gtk::subclass::prelude::*; use qrcode::QrCode; -use tracing::debug; +use tracing::{debug, warn}; use crate::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE}; use application::CredentialsUi; @@ -118,7 +118,9 @@ impl ViewModel { { let tx = view_model.imp().tx.borrow(); let tx = tx.as_ref().expect("tx to exist"); - tx.send_blocking(ViewEvent::Initiated).unwrap(); + if tx.send_blocking(ViewEvent::Initiated).is_err() { + warn!("Request ended before the UI started"); + } } view_model @@ -325,7 +327,9 @@ impl ViewModel { let id = button.widget_name().to_string(); let tx = tx.clone(); glib::spawn_future_local(async move { - tx.send(ViewEvent::CredentialSelected(id)).await.unwrap(); + if tx.send(ViewEvent::CredentialSelected(id)).await.is_err() { + warn!("Request ended before the credential selection was handled"); + } }); }); button.into() @@ -387,7 +391,11 @@ impl ViewModel { async fn send_event(&self, event: ViewEvent) { let tx = self.get_sender(); - tx.send(event).await.unwrap(); + if tx.send(event).await.is_err() { + // The request's event loop has ended, e.g. because the caller + // went away; the UI closes with it. + warn!("Request ended before the UI event was handled"); + } } }