network: don't cancel heartbeat requests

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.
This commit is contained in:
Henry de Valence 2020-12-01 13:24:13 -08:00 committed by Deirdre Connolly
parent 69ba5584f3
commit bfbc737b6c
1 changed files with 20 additions and 6 deletions

View File

@ -460,21 +460,35 @@ where
let shutdown_rx_ref = Pin::new(&mut shutdown_rx); let shutdown_rx_ref = Pin::new(&mut shutdown_rx);
match future::select(interval_stream.next(), shutdown_rx_ref).await { match future::select(interval_stream.next(), shutdown_rx_ref).await {
Either::Left(_) => { Either::Left(_) => {
// We don't wait on a response because heartbeats are checked let (tx, rx) = oneshot::channel();
// internally to the connection logic, we just need a separate let request = Request::Ping(Nonce::default());
// task (this one) to generate them. tracing::trace!(?request, "queueing heartbeat request");
let (request_tx, _) = oneshot::channel();
if server_tx if server_tx
.send(ClientRequest { .send(ClientRequest {
request: Request::Ping(Nonce::default()), request,
tx: request_tx, tx,
span: tracing::Span::current(), span: tracing::Span::current(),
}) })
.await .await
.is_err() .is_err()
{ {
tracing::trace!(
"error sending heartbeat request, shutting down"
);
return; 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 Either::Right(_) => return, // got shutdown signal
} }