Skip to content

Commit

Permalink
Undeclare matching_listener explicitly to avoid deadlock. (#312)
Browse files Browse the repository at this point in the history
It will cause duplicate messages.

Signed-off-by: ChenYing Kuo <evshary@gmail.com>
  • Loading branch information
evshary authored Oct 29, 2024
1 parent 5e99b5a commit 49f8a8b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions zenoh-plugin-ros2dds/src/route_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::{

pub struct ZPublisher {
publisher: Arc<Publisher<'static>>,
_matching_listener: zenoh::pubsub::MatchingListener<()>,
matching_listener: Option<zenoh::pubsub::MatchingListener<()>>,
_cache: Option<PublicationCache>,
cache_size: usize,
}
Expand Down Expand Up @@ -113,6 +113,13 @@ pub struct RoutePublisher {
impl Drop for RoutePublisher {
fn drop(&mut self) {
self.deactivate_dds_reader();
let matching_listener =
std::mem::replace(&mut self.zenoh_publisher.matching_listener, None);
if let Some(matching_listener) = matching_listener {
if let Err(e) = matching_listener.undeclare().wait() {
tracing::warn!("Unable to undeclare matching_listener: {e:?}");
}
}
}
}

Expand Down Expand Up @@ -285,7 +292,7 @@ impl RoutePublisher {
context,
zenoh_publisher: ZPublisher {
publisher,
_matching_listener: matching_listener,
matching_listener: Some(matching_listener),
_cache: cache,
cache_size,
},
Expand Down

0 comments on commit 49f8a8b

Please sign in to comment.