Skip to content

Commit

Permalink
Don't drop the request sender before we finish reading the response
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kayabaNerve committed Nov 5, 2023
1 parent 360b264 commit deecd77
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions coins/monero/src/rpc/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit deecd77

Please sign in to comment.