Skip to content
Merged
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ae0765f
fix(data): a cancelled run stops the program it started, and a progra…
MikeFTV Nov 26, 2026
7e996e4
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
3bea3ba
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
ba5b308
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
61cd4bd
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
8ed7fb0
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
e2f0237
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
cd986dd
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
c06dd1c
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
cef93df
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
052649f
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
3ee8205
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
b0a31ae
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
1120a56
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
c1b624d
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
8074063
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
f5a2a92
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
4806482
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
b2bd158
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
bf42293
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
86c4341
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
b3cd5a8
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
5a203ad
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
517dc6d
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
0db3415
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
4ef85e7
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
b3486db
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
012752e
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
93265f4
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
1d0bae9
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
c1e5525
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
138f7b6
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
ee865e8
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
cee6edb
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 26, 2026
0177ab4
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
7dda985
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
4e2da7d
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
2e51565
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
61e6978
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
1570f7f
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
fd8e6cc
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
bcc4ee7
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
bcce6ec
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
89766a8
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
aa653ee
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
948e518
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
2632453
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
7b42358
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
9d3a087
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
78a3d13
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
5ac2e6f
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
ff76442
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
d8a40f6
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
ef3c40e
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
34b65ec
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
c00ca9e
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
fe172b8
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
4f4e562
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
ceeb8c4
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
f2fff64
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
7859b60
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
af4964a
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
89c03ed
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
d879975
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
9429720
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
ef92bf1
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
c402c9b
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
f6e6fef
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
e0eabbe
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
ca52ebb
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
b4400d7
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
d66afdf
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
203dff9
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
1f5afb9
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
423d0a0
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
febcb46
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
0a8ceed
Merge branch 'main' into fix/external-run-cancel
MikeFTV Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions crates/data/src/source/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ pub(crate) fn reload_workspace(cache: &Path) -> std::io::Result<std::sync::Arc<R
}

/// Runs a program, reading its output as it comes (so a chatty one can't block on a full pipe) and
/// killing it if it runs past `timeout`. `what` names it in the timeout error.
/// killing it if it runs past `timeout` or its run is cancelled ([`crate::progress`], which
/// [`crate::DataError`] reports as `Cancelled`). `what` names it in the timeout error. Each of its two
/// outputs keeps its first 64 MiB; the rest is read and dropped.
pub(crate) fn output(c: Command, timeout: std::time::Duration, what: &str) -> std::io::Result<std::process::Output> {
output_with_budget(c, timeout, what, None)
}
Expand Down Expand Up @@ -161,6 +163,9 @@ pub(crate) fn output_with_budget(
run(c, timeout, what, workspace, None)
}

/// The most of a program's standard output, and of its standard error, that is kept.
const PIPE_LIMIT: u64 = 64 << 20;

fn run(
mut c: Command,
timeout: std::time::Duration,
Expand Down Expand Up @@ -192,11 +197,14 @@ fn run(
return Err(e);
}
}
// Keeps the first `PIPE_LIMIT` bytes and reads the rest into the void, so a program that prints
// without end can't fill the memory, and can't block on a full pipe either.
let drain = |p: Option<Box<dyn Read + Send>>| {
std::thread::Builder::new().spawn(move || {
let mut buf = Vec::new();
if let Some(mut p) = p {
let _ = p.read_to_end(&mut buf);
let _ = p.by_ref().take(PIPE_LIMIT).read_to_end(&mut buf);
let _ = std::io::copy(&mut p, &mut std::io::sink());
}
buf
})
Expand All @@ -219,6 +227,10 @@ fn run(
{
break Err(e);
}
// Cancel: the program is killed below, as for a timeout, and the run ends as cancelled.
if let Err(e) = crate::progress::check() {
break Err(std::io::Error::other(e));
}
match child.try_wait() {
Ok(Some(st)) => {
// The child can finish writing between the scan and try_wait.
Expand Down Expand Up @@ -557,4 +569,44 @@ mod tests {
std::os::unix::fs::symlink(outside.path(), dir.path().join("link")).unwrap();
assert!(check_workspace(dir.path(), 0, "GDAL").is_ok());
}

/// Cancel ends the program at the next 50 ms look, not at the timeout, and says so as `Cancelled`.
#[cfg(unix)]
#[test]
fn a_cancelled_run_kills_the_program() {
use crate::progress::{self, tests::Counted};
use std::sync::{Arc, atomic::Ordering};
for budgeted in [false, true] {
let dir = tempfile::tempdir().unwrap();
let probe = Arc::new(Counted { after_checks: Some(3), ..Default::default() });
let _guard = progress::install(Some(probe.clone()));
let mut c = Command::new("sleep");
c.arg("60");
let start = std::time::Instant::now();
let workspace = budgeted.then_some((dir.path(), 1024));
let e = output_with_budget(c, std::time::Duration::from_secs(120), "sleep", workspace).unwrap_err();
assert!(matches!(crate::DataError::from(e), crate::DataError::Cancelled));
assert!(start.elapsed() < std::time::Duration::from_secs(10), "the program was killed when cancelled, not at its timeout");
assert!(probe.checks.load(Ordering::Relaxed) >= 4, "the loop asked at each poll");
}
let out = output(Command::new("true"), std::time::Duration::from_secs(60), "true").unwrap();
assert!(out.status.success(), "without a probe a program only runs");
}

/// A program that prints more than the limit keeps the start of it and still finishes: its
/// pipes are read to the end.
#[cfg(unix)]
#[test]
fn output_past_the_limit_is_dropped_and_the_program_finishes() {
let mut c = Command::new("/bin/sh");
c.args(["-c", "head -c 100000000 /dev/zero; head -c 70000000 /dev/zero >&2; echo done >&2"]);
let out = output(c, std::time::Duration::from_secs(120), "printer").unwrap();
assert!(out.status.success());
assert_eq!(out.stdout.len() as u64, PIPE_LIMIT);
assert_eq!(out.stderr.len() as u64, PIPE_LIMIT, "the limit is per pipe");
let mut c = Command::new("/bin/sh");
c.args(["-c", "echo small; echo oops >&2"]);
let out = output(c, std::time::Duration::from_secs(60), "printer").unwrap();
assert_eq!((out.stdout.as_slice(), out.stderr.as_slice()), (&b"small\n"[..], &b"oops\n"[..]));
}
}
Loading