From 7ab8bd7240df9a05259ae59df8e20dab3e23d5d5 Mon Sep 17 00:00:00 2001 From: John Sanchirico <59657471+sanchirico@users.noreply.github.com> Date: Sun, 1 Feb 2026 22:08:01 -0500 Subject: [PATCH] fix(linux-rust): Prevent pulseaudio panic from crashing app (#443) Wrap set_card_profile_sync call in std::panic::catch_unwind to handle panics in libpulse-binding when deactivating A2DP profile. --- linux-rust/src/media_controller.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/linux-rust/src/media_controller.rs b/linux-rust/src/media_controller.rs index adaef4a..73fbf24 100644 --- a/linux-rust/src/media_controller.rs +++ b/linux-rust/src/media_controller.rs @@ -902,8 +902,16 @@ impl MediaController { info!("Deactivating A2DP profile for AirPods by setting to off"); + // Use catch_unwind to prevent panics in libpulse-binding from crashing the app let success = - tokio::task::spawn_blocking(move || set_card_profile_sync(device_index, "off")) + tokio::task::spawn_blocking(move || { + std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + set_card_profile_sync(device_index, "off") + })).unwrap_or_else(|e| { + warn!("Panic in set_card_profile_sync: {:?}", e); + false + }) + }) .await .unwrap_or(false);