Process-wide concurrency + Cancellation ownership fixes

This commit is contained in:
Alexey
2026-09-23 22:30:51 +03:00
parent baa9bfbb01
commit f1107c21d9
47 changed files with 2177 additions and 762 deletions
+22 -14
View File
@@ -3,6 +3,8 @@ use tokio::process::Command;
use crate::util::trusted_command::resolve_trusted_helper;
const COMMAND_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
pub(super) async fn run_command(
binary: &str,
args: &[&str],
@@ -18,21 +20,26 @@ pub(super) async fn run_command(
}
command.stdout(std::process::Stdio::null());
command.stderr(std::process::Stdio::piped());
command.kill_on_drop(true);
let mut child = command
.spawn()
.map_err(|e| format!("spawn {binary} failed: {e}"))?;
if let Some(blob) = stdin
&& let Some(mut writer) = child.stdin.take()
{
writer
.write_all(blob.as_bytes())
let output = tokio::time::timeout(COMMAND_TIMEOUT, async move {
if let Some(blob) = stdin
&& let Some(mut writer) = child.stdin.take()
{
writer
.write_all(blob.as_bytes())
.await
.map_err(|e| format!("stdin write {binary} failed: {e}"))?;
}
child
.wait_with_output()
.await
.map_err(|e| format!("stdin write {binary} failed: {e}"))?;
}
let output = child
.wait_with_output()
.await
.map_err(|e| format!("wait {binary} failed: {e}"))?;
.map_err(|e| format!("wait {binary} failed: {e}"))
})
.await
.map_err(|_| format!("{binary} timed out after {}s", COMMAND_TIMEOUT.as_secs()))??;
if output.status.success() {
return Ok(());
}
@@ -48,10 +55,11 @@ pub(super) async fn run_command_stdout(binary: &str, args: &[&str]) -> Result<St
let Some(command_path) = resolve_trusted_helper(binary) else {
return Err(format!("{binary} is not available"));
};
let output = Command::new(command_path)
.args(args)
.output()
let mut command = Command::new(command_path);
command.args(args).kill_on_drop(true);
let output = tokio::time::timeout(COMMAND_TIMEOUT, command.output())
.await
.map_err(|_| format!("{binary} timed out after {}s", COMMAND_TIMEOUT.as_secs()))?
.map_err(|e| format!("wait {binary} failed: {e}"))?;
if output.status.success() {
return Ok(String::from_utf8_lossy(&output.stdout).to_string());