feat: add timeout for new VM request
This commit is contained in:
parent
a1664d61e4
commit
8fa8a64862
@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
pub use crate::constants::{
|
||||
ACCOUNT, ACTIVE_APP, ACTIVE_VM, DB_SCHEMA_FILE, DELETED_VM, ID_ALPHABET, NEW_VM_REQ,
|
||||
@ -24,6 +24,8 @@ pub enum Error {
|
||||
DaemonConnection(#[from] tokio::sync::mpsc::error::SendError<DaemonNotification>),
|
||||
#[error(transparent)]
|
||||
StdIo(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
TimeOut(#[from] tokio::time::error::Elapsed),
|
||||
}
|
||||
|
||||
pub async fn db_connection(
|
||||
@ -328,6 +330,7 @@ impl NewVmResp {
|
||||
let mut args_stream =
|
||||
resp.stream::<Notification<detee_shared::snp::pb::vm_proto::MeasurementArgs>>(1)?;
|
||||
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
loop {
|
||||
tokio::select! {
|
||||
new_vm_req_notif = new_vm_stream.next() => {
|
||||
@ -336,7 +339,7 @@ impl NewVmResp {
|
||||
match new_vm_req_notif {
|
||||
Ok(new_vm_req_notif) => {
|
||||
if new_vm_req_notif.action == surrealdb::Action::Update && !new_vm_req_notif.data.error.is_empty() {
|
||||
return Ok(Self::Error(vm_id.to_string(), new_vm_req_notif.data.error));
|
||||
return Ok::<NewVmResp, Error>(Self::Error(vm_id.to_string(), new_vm_req_notif.data.error));
|
||||
};
|
||||
},
|
||||
Err(e) => return Err(e.into()),
|
||||
@ -357,6 +360,7 @@ impl NewVmResp {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).await?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,6 +625,7 @@ impl BrainVmCli for BrainVmCliForReal {
|
||||
new_vm_req.submit(&self.db).await?;
|
||||
|
||||
match oneshot_rx.await {
|
||||
Ok(Err(db::Error::TimeOut(_))) => Err(Status::deadline_exceeded("Request failed due to timeout. Please try again later or contact the DeTEE devs team.")),
|
||||
Ok(new_vm_resp) => Ok(Response::new(new_vm_resp?.into())),
|
||||
Err(e) => {
|
||||
log::error!("Something weird happened. Reached error {e:?}");
|
||||
|
Loading…
Reference in New Issue
Block a user