Skip to content

Commit

Permalink
network: don't cancel heartbeat requests
Browse files Browse the repository at this point in the history
The cancellation implementation changes made to the connection state machine
mean that if a response oneshot is dropped, the connection will avoid
cancelling the request.  So the heartbeat task does have to wait on the response.
  • Loading branch information
hdevalence authored and dconnolly committed Dec 2, 2020
1 parent 69ba558 commit bfbc737
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions zebra-network/src/peer/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,35 @@ where
let shutdown_rx_ref = Pin::new(&mut shutdown_rx);
match future::select(interval_stream.next(), shutdown_rx_ref).await {
Either::Left(_) => {
// We don't wait on a response because heartbeats are checked
// internally to the connection logic, we just need a separate
// task (this one) to generate them.
let (request_tx, _) = oneshot::channel();
let (tx, rx) = oneshot::channel();
let request = Request::Ping(Nonce::default());
tracing::trace!(?request, "queueing heartbeat request");
if server_tx
.send(ClientRequest {
request: Request::Ping(Nonce::default()),
tx: request_tx,
request,
tx,
span: tracing::Span::current(),
})
.await
.is_err()
{
tracing::trace!(
"error sending heartbeat request, shutting down"
);
return;
}
// Heartbeats are checked internally to the
// connection logic, but we need to wait on the
// response to avoid canceling the request.
match rx.await {
Ok(_) => tracing::trace!("got heartbeat response"),
Err(_) => {
tracing::trace!(
"error awaiting heartbeat response, shutting down"
);
return;
}
}
}
Either::Right(_) => return, // got shutdown signal
}
Expand Down

0 comments on commit bfbc737

Please sign in to comment.