Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(p2p): disable sending message when not ready to prevent busy loop #5032

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion p2p/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ mod run {
idle_interval.reset();
ping_interval.reset();
}
result = message_sender.send() => {
// `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() => {
Erigara marked this conversation as resolved.
Show resolved Hide resolved
if let Err(error) = result {
iroha_logger::error!(%error, "Failed to send message to peer.");
break;
Expand Down Expand Up @@ -427,6 +432,11 @@ mod run {
}
Ok(())
}

/// Check if message sender has data ready to be sent.
fn ready(&self) -> bool {
!self.queue.is_empty()
}
}

/// Either message or ping
Expand Down
Loading