Skip to content

Commit

Permalink
fix: make rx task close the link properly in low-latency transport (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan authored May 30, 2024
1 parent 3118d31 commit 009f666
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions io/zenoh-transport/src/unicast/lowlatency/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TransportUnicastLowlatency {
let token = self.token.child_token();

let c_transport = self.clone();
let task = async move {
let rx_task = async move {
let guard = zasyncread!(c_transport.link);
let link_rx = guard.as_ref().unwrap().rx();
drop(guard);
Expand All @@ -165,7 +165,7 @@ impl TransportUnicastLowlatency {
zenoh_sync::RecyclingObjectPool::new(n, move || vec![0_u8; mtu].into_boxed_slice())
};

let res = loop {
loop {
// Retrieve one buffer
let mut buffer = pool.try_take().unwrap_or_else(|| pool.alloc());

Expand All @@ -188,25 +188,29 @@ impl TransportUnicastLowlatency {
break ZResult::Ok(());
}
}
};
}
};

tracing::debug!(
"[{}] Rx task finished with result {:?}",
c_transport.manager.config.zid,
res
);
if res.is_err() {
let c_transport = self.clone();
self.tracker.spawn_on(
async move {
let res = rx_task.await;
tracing::debug!(
"[{}] <on rx exit> finalizing transport with peer: {}",
"[{}] Rx task finished with result {:?}",
c_transport.manager.config.zid,
c_transport.config.zid
res
);
let _ = c_transport.finalize(0).await;
}
ZResult::Ok(())
};

self.tracker.spawn_on(task, &ZRuntime::TX);
if res.is_err() {
tracing::debug!(
"[{}] <on rx exit> finalizing transport with peer: {}",
c_transport.manager.config.zid,
c_transport.config.zid
);
let _ = c_transport.finalize(0).await;
}
},
&ZRuntime::RX,
);
}
}

Expand Down

0 comments on commit 009f666

Please sign in to comment.