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

Rumenov/canceiofhg #2468

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
36 changes: 17 additions & 19 deletions rs/p2p/consensus_manager/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,10 @@ async fn send_transmit_to_all_peers(

if !is_initiated {
let child_token = cancellation_token.child_token();
let child_token_clone = child_token.clone();
metrics.send_view_send_to_peer_total.inc();

let transport = transport.clone();
let body = body.clone();
let route = route.clone();

let send_future = async move {
select! {
_ = send_transmit_to_peer(transport, body, peer, route) => {},
_ = child_token.cancelled() => {},
}
};

in_progress_transmissions.spawn_on(send_future, &rt_handle);
initiated_transmissions.insert(peer, (connection_id, child_token_clone));
let send_fut = send_transmit_to_peer(transport.clone(), body.clone(), peer, route.clone(), child_token.clone());
in_progress_transmissions.spawn_on(send_fut, &rt_handle);
initiated_transmissions.insert(peer, (connection_id, child_token));
}
}
}
Expand All @@ -310,6 +298,7 @@ async fn send_transmit_to_peer(
message: Bytes,
peer: NodeId,
route: String,
cancellation_token: CancellationToken,
) {
let mut backoff = ExponentialBackoffBuilder::new()
.with_initial_interval(MIN_BACKOFF_INTERVAL)
Expand All @@ -324,13 +313,22 @@ async fn send_transmit_to_peer(
.body(message.clone())
.expect("Building from typed values");

// TODO: NET-1748
if transport.rpc(&peer, request).await.is_ok() {
return;
select! {
// TODO: NET-1748
rpc_result = transport.rpc(&peer, request) => {
if rpc_result.is_ok() {
return;
}
},
_ = cancellation_token.cancelled() => return,
}

let backoff_duration = backoff.next_backoff().unwrap_or(MAX_BACKOFF_INTERVAL);
time::sleep(backoff_duration).await;
let timeout = time::sleep(backoff_duration);
select! {
_ = timeout => (),
_ = cancellation_token.cancelled() => return,
}
}
}

Expand Down
Loading