Skip to content

Commit c353af5

Browse files
committed
Time out delta generation after 1h
1 parent 6acc948 commit c353af5

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/ostree.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
pub use flat_manager_common::ostree::*;
22

33
use std::path::Path;
4+
use std::process::Stdio;
5+
use std::time::Duration;
46
use tokio::process::Command;
7+
use tokio::time::timeout;
58

69
pub async fn generate_delta_async(repo_path: &Path, delta: &Delta) -> Result<(), OstreeError> {
10+
let command = "flatpak build-update-repo";
711
let mut cmd = Command::new("flatpak");
812

913
cmd.arg("build-update-repo")
@@ -15,10 +19,23 @@ pub async fn generate_delta_async(repo_path: &Path, delta: &Delta) -> Result<(),
1519
};
1620

1721
cmd.arg(repo_path);
22+
cmd.stdin(Stdio::null())
23+
.stdout(Stdio::piped())
24+
.stderr(Stdio::piped())
25+
.kill_on_drop(true);
1826

1927
log::info!("Generating delta {}", delta);
20-
let output = cmd.output().await.map_err(|e| {
21-
OstreeError::ExecFailed("flatpak build-update-repo".to_string(), e.to_string())
22-
})?;
23-
result_from_output(output, "flatpak build-update-repo")
28+
let child = cmd
29+
.spawn()
30+
.map_err(|e| OstreeError::ExecFailed(command.to_string(), e.to_string()))?;
31+
let output = timeout(Duration::from_secs(3600), child.wait_with_output())
32+
.await
33+
.map_err(|_| {
34+
OstreeError::CommandFailed(
35+
command.to_string(),
36+
format!("Timed out after 3600 seconds while generating delta {delta}"),
37+
)
38+
})?
39+
.map_err(|e| OstreeError::ExecFailed(command.to_string(), e.to_string()))?;
40+
result_from_output(output, command)
2441
}

0 commit comments

Comments
 (0)