From deecd77aec26dba4631fd452b13ba22f4b555b13 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 4 Nov 2023 22:55:47 -0400 Subject: [PATCH] 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. --- coins/monero/src/rpc/http.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coins/monero/src/rpc/http.rs b/coins/monero/src/rpc/http.rs index 803e35c5..6489d052 100644 --- a/coins/monero/src/rpc/http.rs +++ b/coins/monero/src/rpc/http.rs @@ -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(); }