[pbs-devel] [PATCH proxmox-backup] proxmox-restore-daemon: keep daemon active during extract api call

Dominik Csapak d.csapak at proxmox.com
Fri May 14 10:42:20 CEST 2021


we only called watchdog_ping on the start of an api call, which meant
that if a single zip/pxar download took longer than 10 minutes
(which can happen on larger vms/slower connections), we shut-down
the vm and cancelled the download.

instead, spawn a second future, that polls both a sleep and the extract
handle, and ping the watchdog every 60 seconds

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/bin/proxmox_restore_daemon/api.rs | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs
index f1d601ce..eafff6e2 100644
--- a/src/bin/proxmox_restore_daemon/api.rs
+++ b/src/bin/proxmox_restore_daemon/api.rs
@@ -277,7 +277,7 @@ fn extract(
 
         let (mut writer, reader) = tokio::io::duplex(1024 * 64);
 
-        if pxar {
+        let handle = if pxar {
             tokio::spawn(async move {
                 let result = async move {
                     // pxar always expects a directory as it's root, so to accommodate files as
@@ -333,7 +333,7 @@ fn extract(
                 if let Err(err) = result {
                     error!("pxar streaming task failed - {}", err);
                 }
-            });
+            })
         } else {
             tokio::spawn(async move {
                 let result = async move {
@@ -355,11 +355,22 @@ fn extract(
                 if let Err(err) = result {
                     error!("file or dir streaming task failed - {}", err);
                 }
-            });
-        }
+            })
+        };
 
         let stream = tokio_util::io::ReaderStream::new(reader);
 
+        tokio::spawn(async move {
+            let mut handle = handle.fuse();
+            let interval = std::time::Duration::new(60, 0);
+            loop {
+                futures::select! {
+                    _ = handle => break,
+                    _ = tokio::time::sleep(interval).fuse() => watchdog_ping(),
+                }
+            }
+        });
+
         let body = Body::wrap_stream(stream);
         Ok(Response::builder()
             .status(StatusCode::OK)
-- 
2.20.1






More information about the pbs-devel mailing list