diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-22 20:42:23 +0000 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-22 20:42:23 +0000 |
commit | 73574ab43e5dca999545c931b959f2a3cbacea95 (patch) | |
tree | 141fd2c09929f6a1c701e20196497e836b35879f /src/rpc_client.rs | |
parent | 897fafa8db61ee94c40d233332940e3e470d1d03 (diff) | |
download | garage-73574ab43e5dca999545c931b959f2a3cbacea95.tar.gz garage-73574ab43e5dca999545c931b959f2a3cbacea95.zip |
Fix in rpc_client (see comment in code)
Diffstat (limited to 'src/rpc_client.rs')
-rw-r--r-- | src/rpc_client.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/rpc_client.rs b/src/rpc_client.rs index aeb66956..eb02213a 100644 --- a/src/rpc_client.rs +++ b/src/rpc_client.rs @@ -117,10 +117,20 @@ impl<M: RpcMessage + 'static> RpcClient<M> { 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::<Vec<_>>().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 { |