From 48ce3d00a4c83bd6e732f4adf53f04177a86dc31 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 26 Jan 2022 16:04:41 +0100 Subject: [PATCH] file restore: always wait up to 25s the timeout for connecting may be much shorter if we get a response (which doesn't needs to be Ok, e.g., "Connection refused"), so instead of trying a fixed amount of 60 times lets try for 25s independent of how often that will be then. Signed-off-by: Thomas Lamprecht --- proxmox-file-restore/src/qemu_helper.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proxmox-file-restore/src/qemu_helper.rs b/proxmox-file-restore/src/qemu_helper.rs index 79bfb1ec..9af3ab46 100644 --- a/proxmox-file-restore/src/qemu_helper.rs +++ b/proxmox-file-restore/src/qemu_helper.rs @@ -3,7 +3,7 @@ use std::fs::{File, OpenOptions}; use std::io::prelude::*; use std::os::unix::io::AsRawFd; use std::path::PathBuf; -use std::time::Duration; +use std::time::{Instant, Duration}; use anyhow::{bail, format_err, Error}; use tokio::time; @@ -303,7 +303,9 @@ pub async fn start_vm( // QEMU has started successfully, now wait for virtio socket to become ready let pid_t = Pid::from_raw(pid); - for _ in 0..60 { + + let start_poll = Instant::now(); + loop { let client = VsockClient::new(cid as i32, DEFAULT_VSOCK_PORT, Some(ticket.to_owned())); if let Ok(Ok(_)) = time::timeout(Duration::from_secs(2), client.get("api2/json/status", None)).await @@ -319,6 +321,9 @@ pub async fn start_vm( if kill(pid_t, None).is_err() { // check if QEMU process exited in between bail!("VM exited before connection could be established"); } + if Instant::now().duration_since(start_poll) > Duration::from_secs(25) { + break; + } time::sleep(Duration::from_millis(200)).await; }