Skip to content

Commit 740e776

Browse files
committed
fix: handle poisoned mutex in ctrl_c subscriber registration
1 parent 482be45 commit 740e776

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rt/src/threads/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ pub fn ctrl_c() -> impl FnOnce() + Send + 'static {
7979
let subscribers = CTRL_C_SUBSCRIBERS.get_or_init(|| {
8080
ctrlc::set_handler(|| {
8181
if let Some(subs) = CTRL_C_SUBSCRIBERS.get() {
82-
if let Ok(guard) = subs.lock() {
83-
for tx in guard.iter() {
84-
let _ = tx.send(());
85-
}
82+
let guard = subs
83+
.lock()
84+
.unwrap_or_else(|poisoned| poisoned.into_inner());
85+
for tx in guard.iter() {
86+
let _ = tx.send(());
8687
}
8788
}
8889
})
@@ -92,9 +93,10 @@ pub fn ctrl_c() -> impl FnOnce() + Send + 'static {
9293

9394
// Create a new subscriber channel
9495
let (tx, rx) = std_mpsc::channel();
95-
if let Ok(mut guard) = subscribers.lock() {
96-
guard.push(tx);
97-
}
96+
subscribers
97+
.lock()
98+
.unwrap_or_else(|poisoned| poisoned.into_inner())
99+
.push(tx);
98100

99101
move || {
100102
let _ = rx.recv();

0 commit comments

Comments
 (0)