From 73574ab43e5dca999545c931b959f2a3cbacea95 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 22 Apr 2020 20:42:23 +0000 Subject: [PATCH] Fix in rpc_client (see comment in code) --- src/rpc_client.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rpc_client.rs b/src/rpc_client.rs index aeb669568..eb02213ad 100644 --- a/src/rpc_client.rs +++ b/src/rpc_client.rs @@ -117,10 +117,20 @@ impl RpcClient { if results.len() >= stop_after { // Continue requests in background // TODO: make this optionnal (only usefull for write requests) - self.clone().background.spawn_cancellable(async move { + + // Continue the remaining requests immediately using tokio::spawn + // but enqueue a task in the background runner + // to ensure that the process won't exit until the requests are done + // (if we had just enqueued the resp_stream.collect directly in the background runner, + // the requests might have been put on hold in the background runner's queue, + // in which case they might timeout or otherwise fail) + let wait_finished_fut = tokio::spawn(async move { resp_stream.collect::>().await; Ok(()) }); + self.clone().background.spawn(wait_finished_fut.map(|x| { + x.unwrap_or_else(|e| Err(Error::Message(format!("Await failed: {}", e)))) + })); Ok(results) } else {