From 530aeff5bec513e4e7ef37981521d02cc40cdfa6 Mon Sep 17 00:00:00 2001 From: Shanin Roman <40040452+Erigara@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:56:47 +0300 Subject: [PATCH] refacrot(p2p): add clarification comment for `message_sender.send()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ⭐️NINIKA⭐️ Signed-off-by: Shanin Roman <40040452+Erigara@users.noreply.github.com> --- p2p/src/peer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/src/peer.rs b/p2p/src/peer.rs index 9b8ff2c0bf4..71e0c59094e 100644 --- a/p2p/src/peer.rs +++ b/p2p/src/peer.rs @@ -261,6 +261,11 @@ mod run { idle_interval.reset(); ping_interval.reset(); } + // `message_sender.send()` is safe to be cancelled, it won't advance the queue or write anything if another branch completes first. + // + // We need to conditionally disable it in case there is no data is to be sent, otherwise `message_sender.send()` will complete immediately + // + // The only source of data to be sent is other branches of this loop, so we do not need any async waiting mechanism for waiting for readiness. result = message_sender.send(), if message_sender.ready() => { if let Err(error) = result { iroha_logger::error!(%error, "Failed to send message to peer.");