From aa805153d307e71f2bc190e5d0da9ece5c9cae96 Mon Sep 17 00:00:00 2001 From: Mateo Fernandez Date: Thu, 30 May 2024 11:59:25 +0200 Subject: [PATCH] fix(vmm): process message in a tokio thread to not block the current flow Signed-off-by: Mateo Fernandez --- src/vmm/src/grpc/server.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/vmm/src/grpc/server.rs b/src/vmm/src/grpc/server.rs index 9bac2ad..50a4e24 100644 --- a/src/vmm/src/grpc/server.rs +++ b/src/vmm/src/grpc/server.rs @@ -248,15 +248,17 @@ impl VmmServiceTrait for VmmService { let mut response_stream = client.execute(agent_request).await?; // Process each message as it arrives - while let Some(response) = response_stream.message().await? { - let vmm_response = vmmorchestrator::ExecuteResponse { - stage: response.stage, - stdout: response.stdout, - stderr: response.stderr, - exit_code: response.exit_code, - }; - tx.send(Ok(vmm_response)).await.unwrap(); - } + tokio::spawn(async move { + while let Ok(Some(response)) = response_stream.message().await { + let vmm_response = vmmorchestrator::ExecuteResponse { + stage: response.stage, + stdout: response.stdout, + stderr: response.stderr, + exit_code: response.exit_code, + }; + let _ = tx.send(Ok(vmm_response)).await; + } + }); } Err(e) => { error!("ERROR {:?}", e);