diff --git a/zenoh/src/api/liveliness.rs b/zenoh/src/api/liveliness.rs index bb068b4e52..10788f39e9 100644 --- a/zenoh/src/api/liveliness.rs +++ b/zenoh/src/api/liveliness.rs @@ -385,6 +385,7 @@ impl<'a> LivelinessToken<'a> { } fn undeclare_impl(&mut self) -> ZResult<()> { + // set the flag first to avoid double panic if this function panic self.undeclare_on_drop = false; match self.session.upgrade() { Some(session) => session.undeclare_liveliness(self.state.id), @@ -581,6 +582,7 @@ where session: session.into(), state: sub_state, kind: SubscriberKind::LivelinessSubscriber, + // `size_of::() == 0` means callback-only subscriber undeclare_on_drop: size_of::() > 0, }, handler, diff --git a/zenoh/src/api/publisher.rs b/zenoh/src/api/publisher.rs index 91b27958ec..50f811da3e 100644 --- a/zenoh/src/api/publisher.rs +++ b/zenoh/src/api/publisher.rs @@ -366,6 +366,7 @@ impl<'a> Publisher<'a> { } fn undeclare_impl(&mut self) -> ZResult<()> { + // set the flag first to avoid double panic if this function panic self.undeclare_on_drop = false; #[cfg(feature = "unstable")] { diff --git a/zenoh/src/api/queryable.rs b/zenoh/src/api/queryable.rs index 163d32c011..89938f213b 100644 --- a/zenoh/src/api/queryable.rs +++ b/zenoh/src/api/queryable.rs @@ -544,6 +544,7 @@ pub(crate) struct QueryableInner<'a> { pub(crate) session_id: ZenohId, pub(crate) session: WeakSessionRef<'a>, pub(crate) state: Arc, + // Queryable is undeclared on drop unless its handler is a ZST, i.e. it is callback-only pub(crate) undeclare_on_drop: bool, } @@ -859,6 +860,7 @@ impl<'a, Handler> Queryable<'a, Handler> { } fn undeclare_impl(&mut self) -> ZResult<()> { + // set the flag first to avoid double panic if this function panic self.inner.undeclare_on_drop = false; match self.inner.session.upgrade() { Some(session) => session.close_queryable(self.inner.state.id), @@ -928,6 +930,7 @@ where session_id: session.zid(), session: session.into(), state: qable_state, + // `size_of::() == 0` means callback-only queryable undeclare_on_drop: size_of::() > 0, }, handler: receiver, diff --git a/zenoh/src/api/subscriber.rs b/zenoh/src/api/subscriber.rs index abeb36aa28..7c62e0502d 100644 --- a/zenoh/src/api/subscriber.rs +++ b/zenoh/src/api/subscriber.rs @@ -64,6 +64,7 @@ pub(crate) struct SubscriberInner<'a> { pub(crate) session: WeakSessionRef<'a>, pub(crate) state: Arc, pub(crate) kind: SubscriberKind, + // Subscriber is undeclared on drop unless its handler is a ZST, i.e. it is callback-only pub(crate) undeclare_on_drop: bool, } @@ -334,6 +335,7 @@ where session: session.into(), state: sub_state, kind: SubscriberKind::Subscriber, + // `size_of::() == 0` means callback-only subscriber undeclare_on_drop: size_of::() > 0, }, handler: receiver, @@ -476,6 +478,7 @@ impl<'a, Handler> Subscriber<'a, Handler> { } fn undeclare_impl(&mut self) -> ZResult<()> { + // set the flag first to avoid double panic if this function panic self.inner.undeclare_on_drop = false; match self.inner.session.upgrade() { Some(session) => {