Don't drop the request sender before we finish reading the response

It *looks like* hyper will drop the connection once its request sender is
dropped, regardless of if the last request hasn't had its response completed.
This attempts to resolve some spurious connection errors.
This commit is contained in:
Luke Parker 2023-11-04 22:55:47 -04:00
parent 360b264a0f
commit deecd77aec
No known key found for this signature in database

View file

@ -113,7 +113,6 @@ impl HttpRpc {
.await
.map_err(|e| RpcError::ConnectionError(e.to_string()))?;
let connection_task = tokio::spawn(connection);
connection_task_handle = Some(connection_task.abort_handle());
let mut response = requester
.send_request(request("/".to_string() + route))
@ -151,6 +150,9 @@ impl HttpRpc {
.send_request(request)
.await
.map_err(|e| RpcError::ConnectionError(e.to_string()))?;
// Also embed the requester so it's not dropped, causing the connection to close
connection_task_handle = Some((requester, connection_task.abort_handle()));
}
response
@ -184,7 +186,7 @@ impl HttpRpc {
.map_err(|e| RpcError::ConnectionError(e.to_string()))?
.to_vec();
if let Some(connection_task) = connection_task_handle {
if let Some((_, connection_task)) = connection_task_handle {
// Clean up the connection task
connection_task.abort();
}