Skip to content

Commit 2223e8b

Browse files
MatchingListener deadlock regression test (#2147)
* Add regression test * Disable multicast scouting in existing tests * Fix build * Address review comment
1 parent 39d5180 commit 2223e8b

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

zenoh/tests/matching.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ const TIMEOUT: Duration = Duration::from_secs(60);
2828
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
2929

3030
async fn create_session_pair(locator: &str) -> (Session, Session) {
31-
let config1 = {
32-
let mut config = zenoh::Config::default();
33-
config.scouting.multicast.set_enabled(Some(false)).unwrap();
34-
config
35-
.listen
36-
.endpoints
37-
.set(vec![locator.parse().unwrap()])
38-
.unwrap();
39-
config
40-
};
31+
let mut config1 = zenoh::Config::default();
32+
config1.scouting.multicast.set_enabled(Some(false)).unwrap();
33+
config1
34+
.listen
35+
.endpoints
36+
.set(vec![locator.parse().unwrap()])
37+
.unwrap();
38+
4139
let mut config2 = zenoh::Config::default();
40+
config2.scouting.multicast.set_enabled(Some(false)).unwrap();
4241
config2.set_mode(Some(WhatAmI::Client)).unwrap();
4342
config2
4443
.connect
@@ -77,7 +76,9 @@ async fn zenoh_querier_matching_status_inner(querier_locality: Locality, same_se
7776
let (session1, session2) = match same_session {
7877
false => create_session_pair("tcp/127.0.0.1:18002").await,
7978
true => {
80-
let s1 = ztimeout!(zenoh::open(zenoh::Config::default())).unwrap();
79+
let mut config = zenoh::Config::default();
80+
config.scouting.multicast.set_enabled(Some(false)).unwrap();
81+
let s1 = ztimeout!(zenoh::open(config)).unwrap();
8182
let s2 = s1.clone();
8283
(s1, s2)
8384
}
@@ -182,7 +183,9 @@ async fn zenoh_publisher_matching_status_inner(publisher_locality: Locality, sam
182183
let (session1, session2) = match same_session {
183184
false => create_session_pair("tcp/127.0.0.1:18001").await,
184185
true => {
185-
let s1 = ztimeout!(zenoh::open(zenoh::Config::default())).unwrap();
186+
let mut config = zenoh::Config::default();
187+
config.scouting.multicast.set_enabled(Some(false)).unwrap();
188+
let s1 = ztimeout!(zenoh::open(config)).unwrap();
186189
let s2 = s1.clone();
187190
(s1, s2)
188191
}
@@ -240,3 +243,30 @@ async fn zenoh_publisher_matching_status() -> ZResult<()> {
240243
zenoh_publisher_matching_status_inner(Locality::SessionLocal, false).await;
241244
Ok(())
242245
}
246+
247+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
248+
async fn zenoh_matching_listener_drop_deadlock() {
249+
zenoh_util::init_log_from_env_or("error");
250+
251+
let mut config = zenoh::Config::default();
252+
config.scouting.multicast.set_enabled(Some(false)).unwrap();
253+
let session = ztimeout!(zenoh::open(config)).unwrap();
254+
255+
let querier = std::sync::Arc::new(
256+
session
257+
.declare_querier("zenoh_matching_listener_drop_deadlock")
258+
.await
259+
.unwrap(),
260+
);
261+
let matching_listener = querier
262+
.matching_listener()
263+
.callback({
264+
let querier = querier.clone();
265+
move |_| println!("{}", querier.key_expr())
266+
})
267+
.await
268+
.unwrap();
269+
270+
drop(querier);
271+
drop(matching_listener); // Should not deadlock
272+
}

0 commit comments

Comments
 (0)