From 5650d5dfce2af37c5b44bf7916ca6e42e0c13c17 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 7 Sep 2022 11:58:18 +0200 Subject: [PATCH] Delay dropping of zenoh communication layer to ensure that stop message is sent Zenoh seems to drop the messages in its send queue when the session is closed. The stop messages are critical, so we wait a bit to ensure that they're actually sent. --- apis/rust/node/src/communication/zenoh.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apis/rust/node/src/communication/zenoh.rs b/apis/rust/node/src/communication/zenoh.rs index b0342260..4e44eb4a 100644 --- a/apis/rust/node/src/communication/zenoh.rs +++ b/apis/rust/node/src/communication/zenoh.rs @@ -1,6 +1,6 @@ use super::{CommunicationLayer, Publisher, Subscriber}; use crate::BoxError; -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; use zenoh::{ prelude::{EntityFactory, Priority, Receiver as _, SplitBuffer, ZFuture}, publication::CongestionControl, @@ -53,6 +53,17 @@ impl CommunicationLayer for ZenohCommunicationLayer { } } +impl Drop for ZenohCommunicationLayer { + fn drop(&mut self) { + // wait a bit before closing to ensure that remaining published + // messages are sent out + // + // TODO: create a minimal example to reproduce the dropped messages + // and report this issue in the zenoh repo + std::thread::sleep(Duration::from_secs_f32(1.0)); + } +} + #[derive(Clone)] pub struct ZenohPublisher { publisher: zenoh::publication::Publisher<'static>,