cultmesh-rs: drop a caught wake panic's payload inside its own catch (panic-payload-drop-kills-pump)
Steward decision (coordinator, 2026-11-29): a payload whose Drop panics no longer ends the pump. The docs say a panicking wake aborts the process under panic = abort. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f044832287
commit
4cd51e150f
2 changed files with 36 additions and 2 deletions
|
|
@ -17,7 +17,9 @@
|
|||
//! pump thread after the event is in the queue and counted, so a `try_drain` made inside or after the call sees the
|
||||
//! event; once per delivered event (a snapshot, a commit, `Faulted`, `Disconnected`), not once per batch, so
|
||||
//! coalescing is the consumer's; and it must not block, because a slow wake delays the pump and so RUDP acks and
|
||||
//! resends. A panic in it is caught and discarded: the pump survives and the event stays queued. It may call
|
||||
//! resends. A panic in it is caught and discarded, payload included even when the payload's own drop panics: the
|
||||
//! pump survives and the event stays queued. (Under `panic = "abort"` a panicking wake aborts the process: nothing
|
||||
//! can catch it.) It may call
|
||||
//! `try_drain`, `subscribe`, `unsubscribe` or `resubscribe_all`; the closure exists before the client does, so it
|
||||
//! reaches the client through a `Weak` (or a slot filled after `connect_with_wake` returns) and should hold it only
|
||||
//! weakly: if the owner drops its handle while the wake holds an upgraded one, the wake's handle is the last, and
|
||||
|
|
@ -783,7 +785,10 @@ impl Pump {
|
|||
/// Runs the wake, if any. A panic in it is the consumer's, and the pump survives it.
|
||||
fn notify(&self) {
|
||||
if let Some(wake) = &self.wake {
|
||||
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| wake()));
|
||||
// The payload is dropped inside its own catch: a payload whose drop panics must not end the pump.
|
||||
if let Err(payload) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| wake())) {
|
||||
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || drop(payload)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1648,3 +1648,32 @@ fn the_last_handle_dropped_on_the_pump_thread_ends_the_pump_cleanly() {
|
|||
peer.expect(PeerEvent::Goodbye(b"subscription-closed".to_vec()));
|
||||
assert!(finished.load(Ordering::SeqCst), "the wake ran to its end: dropping the last handle did not panic");
|
||||
}
|
||||
|
||||
/// A panic payload whose own drop panics.
|
||||
struct PayloadBomb;
|
||||
|
||||
impl Drop for PayloadBomb {
|
||||
fn drop(&mut self) {
|
||||
panic!("the payload's drop panics");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wake_that_panics_with_a_payload_whose_drop_panics_does_not_stop_the_pump() {
|
||||
let peer = Peer::start();
|
||||
let (counted, wakes, _tokens) = counting_wake();
|
||||
let calls = AtomicUsize::new(0);
|
||||
let wake = move || {
|
||||
if calls.fetch_add(1, Ordering::SeqCst) == 0 {
|
||||
std::panic::panic_any(PayloadBomb);
|
||||
}
|
||||
counted();
|
||||
};
|
||||
let client = CultMeshRudpSubscriptionClient::connect_with_wake(options(&peer), wake).unwrap();
|
||||
let pump = client.pump_liveness();
|
||||
subscribed(&peer, &client); // the snapshot was queued before its wake panicked
|
||||
peer.send(&single_change("later", "sub-1"));
|
||||
wakes.wait_for(1);
|
||||
assert!(pump.upgrade().is_some(), "the pump is alive");
|
||||
assert_eq!(keys(&drain_events(&client, 1)[0]), ["k"]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue