Skip to content

Commit 7ab8bd7

Browse files
authored
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.
1 parent c852b72 commit 7ab8bd7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

linux-rust/src/media_controller.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,16 @@ impl MediaController {
902902

903903
info!("Deactivating A2DP profile for AirPods by setting to off");
904904

905+
// Use catch_unwind to prevent panics in libpulse-binding from crashing the app
905906
let success =
906-
tokio::task::spawn_blocking(move || set_card_profile_sync(device_index, "off"))
907+
tokio::task::spawn_blocking(move || {
908+
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
909+
set_card_profile_sync(device_index, "off")
910+
})).unwrap_or_else(|e| {
911+
warn!("Panic in set_card_profile_sync: {:?}", e);
912+
false
913+
})
914+
})
907915
.await
908916
.unwrap_or(false);
909917

0 commit comments

Comments
 (0)