From 882742a6aad94ce7b850dd0fbc5610cacaffc4da Mon Sep 17 00:00:00 2001 From: giswqs Date: Fri, 13 Nov 2026 23:34:37 -0500 Subject: [PATCH 1/2] fix(geolibre): a runner just written starts though its file is still busy Starting a program whose file another process still holds open for writing fails with "text file busy". A runner just installed or replaced can be held that moment longer by any process started at the same time, which inherits the open file until it runs its own program. The start is tried again for up to a second. In CI this failed `only_a_supported_download_replaces_the_installed_runner` now and then ("the downloaded v1.8.0 runner doesn't start"), as the tests beside it start programs of their own. --- crates/geolibre/src/runner.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/geolibre/src/runner.rs b/crates/geolibre/src/runner.rs index 9eb2a1951d..2bedbf3e10 100644 --- a/crates/geolibre/src/runner.rs +++ b/crates/geolibre/src/runner.rs @@ -140,10 +140,27 @@ fn output_within(c: Command, limit: Duration) -> Option { output_until(c, &|| (start.elapsed() >= limit).then(|| "timed out".to_string())).ok() } +/// Starts `c`, waiting out a program file that is still held open for writing ("text file +/// busy"): a runner just written (installed, or replaced) can be held a moment longer by another +/// process started at the same time, which inherits the open file until it runs its own program. +/// Tried again for up to a second; any other failure, or a file still busy then, is the error. +fn spawn_when_free(c: &mut Command) -> std::io::Result { + let start = Instant::now(); + loop { + match c.spawn() { + Err(e) if e.kind() == std::io::ErrorKind::ExecutableFileBusy && start.elapsed() < Duration::from_secs(1) => { + std::thread::sleep(Duration::from_millis(10)); + } + started => return started, + } + } +} + /// Runs `c` to completion, unless `stop` gives a reason first (looked at every 20 ms): then the /// process is killed and the reason is the error. Both pipes are drained while it runs. fn output_until(mut c: Command, stop: &dyn Fn() -> Option) -> Result { - let mut child = c.stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn().map_err(|e| e.to_string())?; + c.stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()); + let mut child = spawn_when_free(&mut c).map_err(|e| e.to_string())?; // Drain both pipes on threads while the process runs: a full pipe (large manifests, or // many warnings) would otherwise block it until the time limit. fn drain(mut pipe: impl std::io::Read + Send + 'static) -> std::thread::JoinHandle> { From 7da72a214cbba35d55b01f2fc53002b9ca7758eb Mon Sep 17 00:00:00 2001 From: giswqs Date: Fri, 13 Nov 2026 23:50:38 -0500 Subject: [PATCH 2/2] Address review feedback - The wait for a busy program file looks at the caller's stop condition before each try, so a Cancel, a closed project or a time limit ends it with its reason and nothing is started. --- crates/geolibre/src/runner.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/geolibre/src/runner.rs b/crates/geolibre/src/runner.rs index 2bedbf3e10..add7a816ff 100644 --- a/crates/geolibre/src/runner.rs +++ b/crates/geolibre/src/runner.rs @@ -143,15 +143,21 @@ fn output_within(c: Command, limit: Duration) -> Option { /// Starts `c`, waiting out a program file that is still held open for writing ("text file /// busy"): a runner just written (installed, or replaced) can be held a moment longer by another /// process started at the same time, which inherits the open file until it runs its own program. -/// Tried again for up to a second; any other failure, or a file still busy then, is the error. -fn spawn_when_free(c: &mut Command) -> std::io::Result { +/// Tried again for up to a second, unless `stop` gives a reason first (looked at before each +/// try): then nothing is started and the reason is the error. Any other failure, or a file still +/// busy after the second, is the error. +fn spawn_when_free(c: &mut Command, stop: &dyn Fn() -> Option) -> Result { let start = Instant::now(); loop { match c.spawn() { Err(e) if e.kind() == std::io::ErrorKind::ExecutableFileBusy && start.elapsed() < Duration::from_secs(1) => { + if let Some(why) = stop() { + return Err(why); + } std::thread::sleep(Duration::from_millis(10)); } - started => return started, + Err(e) => return Err(e.to_string()), + Ok(child) => return Ok(child), } } } @@ -160,7 +166,7 @@ fn spawn_when_free(c: &mut Command) -> std::io::Result { /// process is killed and the reason is the error. Both pipes are drained while it runs. fn output_until(mut c: Command, stop: &dyn Fn() -> Option) -> Result { c.stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()); - let mut child = spawn_when_free(&mut c).map_err(|e| e.to_string())?; + let mut child = spawn_when_free(&mut c, stop)?; // Drain both pipes on threads while the process runs: a full pipe (large manifests, or // many warnings) would otherwise block it until the time limit. fn drain(mut pipe: impl std::io::Read + Send + 'static) -> std::thread::JoinHandle> {