From 4d95b8144b305f4f7b221554a0c1984551b5928c Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:35:10 -0600 Subject: [PATCH 1/3] test(node): wait out ETXTBSY in the filtered-pack admission test build_filtered_pack_holds_admission_through_rev_list_reap_on_disconnect writes a fake git and starts build_filtered_pack at once. A concurrent test thread that forks while the script's write descriptor is open hands the child a copy until it execs, so the first exec fails with Text file busy and the future completes early with that error. The test's polling loop then polls the finished future again and panics with 'async fn resumed after completion', which hides the cause. Exec the fake with an argument that hits its no-op branch until it stops returning ETXTBSY. With 8 threads forking in the background the unpatched test failed 4 of 80 runs, each with Text file busy (os error 26) at the early completion; patched, it passed 300 of 300. --- crates/gitlawb-node/src/git/smart_http.rs | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/gitlawb-node/src/git/smart_http.rs b/crates/gitlawb-node/src/git/smart_http.rs index b775c834..e4f27c86 100644 --- a/crates/gitlawb-node/src/git/smart_http.rs +++ b/crates/gitlawb-node/src/git/smart_http.rs @@ -1930,6 +1930,34 @@ mod tests { path } + /// Exec a freshly written fake `git` with `args` until it stops failing with + /// ETXTBSY. + /// + /// A script written and chmodded in a test cannot be exec'd while any process + /// still holds a write descriptor to it. A concurrent test thread that forks in + /// that window hands the child a copy until the child execs, so the first exec + /// fails with "Text file busy". The window closes once that child execs and + /// nothing reopens the file for writing, so one successful exec here means the + /// later ones succeed too. `args` must make the fake exit at once with no side + /// effects. + #[cfg(unix)] + fn wait_until_fake_execs(path: &std::path::Path, args: &[&str]) { + // std has no stable `ErrorKind` for ETXTBSY. + const ETXTBSY: i32 = 26; + for _ in 0..100 { + match std::process::Command::new(path).args(args).status() { + Err(e) if e.raw_os_error() == Some(ETXTBSY) => { + std::thread::sleep(Duration::from_millis(20)); + } + _ => return, + } + } + panic!( + "fake git still ETXTBSY after 100 attempts: {}", + path.display() + ); + } + /// Read a two-line `leader\ngrandchild` pidfile once both lines are present. #[cfg(unix)] fn read_two_pids(pidfile: &std::path::Path) -> Option<(i32, i32)> { @@ -2500,6 +2528,7 @@ mod tests { pack = packfile.display() ); let git_bin = write_fake_git(tmp.path(), &body); + wait_until_fake_execs(&git_bin, &["settle"]); let sem = std::sync::Arc::new(tokio::sync::Semaphore::new(1)); let guard = AdmissionGuard::new(sem.clone().try_acquire_owned().unwrap(), None::<()>); let withheld = HashSet::new(); From dd677473b83fa72978bddcc401327942249a5e76 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:48:37 -0600 Subject: [PATCH 2/3] test(node): settle every smart_http fake git against ETXTBSY Move the ETXTBSY wait from one call site into write_fake_git, so all fake-git tests in the module get it. Mirrors the visibility_pack fixture: an early exit after the shebang, gated on FAKE_GIT_SETTLE, lets the settle exec return at once without running the body. Drops the single-call wait_until_fake_execs helper. --- crates/gitlawb-node/src/git/smart_http.rs | 41 ++++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/crates/gitlawb-node/src/git/smart_http.rs b/crates/gitlawb-node/src/git/smart_http.rs index e4f27c86..b59300ab 100644 --- a/crates/gitlawb-node/src/git/smart_http.rs +++ b/crates/gitlawb-node/src/git/smart_http.rs @@ -1921,35 +1921,37 @@ mod tests { } /// Write an executable fake `git` (named `git`) into `dir`; return its path. + /// + /// Returns only once the script execs, so a caller can spawn it at once. #[cfg(unix)] fn write_fake_git(dir: &std::path::Path, body: &str) -> std::path::PathBuf { use std::os::unix::fs::PermissionsExt as _; + // std has no stable `ErrorKind` for ETXTBSY. + const ETXTBSY: i32 = 26; let path = dir.join("git"); + // Every body starts with a shebang. The line inserted after it lets the + // settle exec below exit at once without running the body. + let (shebang, rest) = body + .split_once('\n') + .expect("a fake git body starts with a shebang line"); + let body = format!("{shebang}\nif [ -n \"$FAKE_GIT_SETTLE\" ]; then exit 0; fi\n{rest}"); std::fs::write(&path, body).unwrap(); std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap(); - path - } - - /// Exec a freshly written fake `git` with `args` until it stops failing with - /// ETXTBSY. - /// - /// A script written and chmodded in a test cannot be exec'd while any process - /// still holds a write descriptor to it. A concurrent test thread that forks in - /// that window hands the child a copy until the child execs, so the first exec - /// fails with "Text file busy". The window closes once that child execs and - /// nothing reopens the file for writing, so one successful exec here means the - /// later ones succeed too. `args` must make the fake exit at once with no side - /// effects. - #[cfg(unix)] - fn wait_until_fake_execs(path: &std::path::Path, args: &[&str]) { - // std has no stable `ErrorKind` for ETXTBSY. - const ETXTBSY: i32 = 26; + // A script written in this process cannot be exec'd while any process still + // holds a write descriptor to it. A concurrent test thread that forks while + // the descriptor above is open hands the child a copy until the child execs, + // so the first exec fails with "Text file busy" and the code under test + // reports a spawn failure. Run the script until that stops, which also + // proves later execs succeed: nothing reopens the file for writing. for _ in 0..100 { - match std::process::Command::new(path).args(args).status() { + match std::process::Command::new(&path) + .env("FAKE_GIT_SETTLE", "1") + .status() + { Err(e) if e.raw_os_error() == Some(ETXTBSY) => { std::thread::sleep(Duration::from_millis(20)); } - _ => return, + _ => return path, } } panic!( @@ -2528,7 +2530,6 @@ mod tests { pack = packfile.display() ); let git_bin = write_fake_git(tmp.path(), &body); - wait_until_fake_execs(&git_bin, &["settle"]); let sem = std::sync::Arc::new(tokio::sync::Semaphore::new(1)); let guard = AdmissionGuard::new(sem.clone().try_acquire_owned().unwrap(), None::<()>); let withheld = HashSet::new(); From a8e14098e901c93459280bd41762be320bee21fc Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:56:43 -0600 Subject: [PATCH 3/3] test(node): fail the fake git settle probe loudly instead of returning early --- crates/gitlawb-node/src/git/smart_http.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/gitlawb-node/src/git/smart_http.rs b/crates/gitlawb-node/src/git/smart_http.rs index b59300ab..7ce6ad04 100644 --- a/crates/gitlawb-node/src/git/smart_http.rs +++ b/crates/gitlawb-node/src/git/smart_http.rs @@ -1948,14 +1948,21 @@ mod tests { .env("FAKE_GIT_SETTLE", "1") .status() { - Err(e) if e.raw_os_error() == Some(ETXTBSY) => { + Ok(status) if status.success() => return path, + Err(e) + if e.raw_os_error() == Some(ETXTBSY) + || e.kind() == std::io::ErrorKind::WouldBlock => + { std::thread::sleep(Duration::from_millis(20)); } - _ => return path, + other => panic!( + "fake git settle probe failed: {other:?}: {}", + path.display() + ), } } panic!( - "fake git still ETXTBSY after 100 attempts: {}", + "fake git still busy or unspawnable after 100 attempts: {}", path.display() ); }