From 49f8a8b6d0ef0e32852a357a2e18aed87ff63b47 Mon Sep 17 00:00:00 2001 From: "ChenYing Kuo (CY)" Date: Tue, 29 Oct 2024 21:06:14 +0800 Subject: [PATCH] Undeclare matching_listener explicitly to avoid deadlock. (#312) It will cause duplicate messages. Signed-off-by: ChenYing Kuo --- zenoh-plugin-ros2dds/src/route_publisher.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zenoh-plugin-ros2dds/src/route_publisher.rs b/zenoh-plugin-ros2dds/src/route_publisher.rs index 1d87d8f..8e9ba5a 100644 --- a/zenoh-plugin-ros2dds/src/route_publisher.rs +++ b/zenoh-plugin-ros2dds/src/route_publisher.rs @@ -51,7 +51,7 @@ use crate::{ pub struct ZPublisher { publisher: Arc>, - _matching_listener: zenoh::pubsub::MatchingListener<()>, + matching_listener: Option>, _cache: Option, cache_size: usize, } @@ -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:?}"); + } + } } } @@ -285,7 +292,7 @@ impl RoutePublisher { context, zenoh_publisher: ZPublisher { publisher, - _matching_listener: matching_listener, + matching_listener: Some(matching_listener), _cache: cache, cache_size, },