Skip to content

Commit

Permalink
Fix MatchingListener drop
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Oct 13, 2023
1 parent 1e44243 commit 5d2ee15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 16 additions & 4 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,16 @@ pub(crate) struct MatchingListenerState {
pub(crate) callback: Callback<'static, MatchingStatus>,
}

#[zenoh_macros::unstable]
impl std::fmt::Debug for MatchingListenerState {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("MatchingListener")
.field("id", &self.id)
.field("key_expr", &self.key_expr)
.finish()
}
}

#[zenoh_macros::unstable]
pub(crate) struct MatchingListenerInner<'a> {
pub(crate) publisher: PublisherRef<'a, 'a>,
Expand Down Expand Up @@ -1199,7 +1209,7 @@ impl SyncResolve for MatchingListenerUndeclaration<'_> {
self.subscriber
.publisher
.session
.matches_unsubscribe(self.subscriber.state.id)
.undeclare_matches_listener_inner(self.subscriber.state.id)
}
}

Expand All @@ -1215,9 +1225,11 @@ impl AsyncResolve for MatchingListenerUndeclaration<'_> {
#[zenoh_macros::unstable]
impl Drop for MatchingListenerInner<'_> {
fn drop(&mut self) {
self.alive = false;
if let Err(e) = self.publisher.session.matches_unsubscribe(self.state.id) {
log::error!("Failed to undeclare MatchingListener: {e}");
if self.alive {
let _ = self
.publisher
.session
.undeclare_matches_listener_inner(self.state.id);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,14 +1577,14 @@ impl Session {
}

#[zenoh_macros::unstable]
pub(crate) fn matches_unsubscribe(&self, sid: usize) -> ZResult<()> {
pub(crate) fn undeclare_matches_listener_inner(&self, sid: usize) -> ZResult<()> {
let mut state = zwrite!(self.state);
if state.matching_listeners.remove(&sid).is_some() {
trace!("matches_unsubscribe({sid})");
if let Some(state) = state.matching_listeners.remove(&sid) {
trace!("undeclare_matches_listener_inner({:?})", state);
Ok(())
} else {
bail!("Failed to unsubscribe matching status: unknown id: {sid}")
Err(zerror!("Unable to find MatchingListener").into())
}
Ok(())
}

pub(crate) fn handle_data(
Expand Down

0 comments on commit 5d2ee15

Please sign in to comment.