Skip to content

Commit 216ca7a

Browse files
committed
Fix rare race potentially leading to panic
1 parent 0ee4706 commit 216ca7a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,11 @@ where
561561
}
562562

563563
// Only clone if we have receivers
564+
// This is not a race condition because after inner gets assigned above (or if the request has been aborted),
565+
// this Arc will be inaccessible from the struct and no new receivers can subscribe
564566
if arc.1.receiver_count() > 0 {
565-
// We have receivers, so we can unwrap safely
566-
// unwrap_or_else because unwrap and expect need Debug
567-
// There is no race condition here because after line 560, this Arc will be inaccessible
568-
// from the struct and no new receivers can subscribe
569-
arc.1
570-
.send(res.clone())
571-
.unwrap_or_else(|_| unreachable!("No receivers after receiver count was checked"));
567+
// That being said, others might still *un*subscribe after the if, so we cannot unwrap here
568+
arc.1.send(res.clone()).ok();
572569
}
573570

574571
Some(res)

0 commit comments

Comments
 (0)