Repository navigation
fix(ci): bump url past RUSTSEC-2026-0592 and deflake tmpdir reclaim test - #128
Conversation
url 2.5.8 is flagged by RUSTSEC-2026-0592 (stack overflow in Url::origin() on nested blob: URLs), failing the dependency audit on every PR. Bump to 2.5.9, which needs form_urlencoded 1.2.3. claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors could fail when another test forked while the claim was held: the child keeps the flock'd open file description until its exec closes it. Retry the reclaim briefly; a descriptor the sleep really inherited still holds the lock past the deadline. Co-authored-by: Cursor <[email protected]>
johayang-amd
left a comment
There was a problem hiding this comment.
Thanks Luka, this unblocks Dependency audit for every open PR and fixes the flaky test from #107. The retry still catches a real leak, since the sleep 30 child would keep the lock past the deadline.
Nit, not blocking: a child that another test forks without exec keeps the lock until it exits, not until an exec, so the comment is slightly narrower than what the retry covers.
|
The retry is in the right place, but the same race is still in five places, and Suggestion: one test-only Patch (2 files, +31 −22)diff --git a/crates/axis-sandbox/src/linux/landlock.rs b/crates/axis-sandbox/src/linux/landlock.rs
index 7f829c0..1431ada 100644
--- a/crates/axis-sandbox/src/linux/landlock.rs
+++ b/crates/axis-sandbox/src/linux/landlock.rs
@@ -1123,6 +1123,29 @@ fn normalize_existing_or_absolute_path(path: &Path) -> Result<PathBuf, String> {
normalize_absolute_path(&resolved)
}
+/// Claims the tmpdir right after an earlier claim was dropped. Tests run in
+/// parallel, and a child another test forks while that claim was held keeps
+/// the lock until it execs or exits, so a held lock is retried for a while.
+#[cfg(test)]
+pub(crate) fn reclaim_tmpdir(
+ workspace: &Path,
+ owner: libc::uid_t,
+ refuse_symlinks: bool,
+) -> Result<TmpdirClaim, String> {
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
+ loop {
+ match claim_tmpdir_for(workspace, owner, refuse_symlinks) {
+ Err(err)
+ if err.contains("another sandbox in this workspace holds it")
+ && std::time::Instant::now() < deadline =>
+ {
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ claim => return claim,
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -1925,7 +1948,7 @@ mod tests {
// The holder ended without removing it, as a killed AXIS does.
drop(held);
- let _claim = claim_tmpdir(dir.path(), None).unwrap();
+ let _claim = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, false).unwrap();
assert!(!tmpdir.exists());
create_tmpdir(dir.path()).unwrap();
}
@@ -1956,7 +1979,7 @@ mod tests {
std::fs::remove_file(&tmpdir).unwrap();
std::fs::create_dir(&tmpdir).unwrap();
- let _claim = claim_tmpdir_for(dir.path(), owner.wrapping_add(1), false).unwrap();
+ let _claim = reclaim_tmpdir(dir.path(), owner.wrapping_add(1), false).unwrap();
assert!(tmpdir.is_dir());
assert!(
create_tmpdir(dir.path())
@@ -2017,23 +2040,15 @@ mod tests {
fn claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors() {
let dir = tempfile::tempdir().unwrap();
for identity in [false, true] {
- let claim = claim_tmpdir_for(dir.path(), unsafe { libc::geteuid() }, identity).unwrap();
+ let claim = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, identity).unwrap();
let mut command = std::process::Command::new("/bin/sleep")
.arg("30")
.spawn()
.unwrap();
drop(claim);
// Only an inherited lock descriptor could keep the workspace locked
- // past the deadline. A command another test forks while the claim is
- // held keeps the lock only until its exec closes the descriptor.
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
- let reclaimed = loop {
- let reclaimed = claim_tmpdir(dir.path(), None);
- if reclaimed.is_ok() || std::time::Instant::now() >= deadline {
- break reclaimed;
- }
- std::thread::sleep(std::time::Duration::from_millis(10));
- };
+ // past the retry.
+ let reclaimed = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, false);
let _ = command.kill();
let _ = command.wait();
assert!(reclaimed.is_ok(), "{identity}: {reclaimed:?}");
diff --git a/crates/axis-sandbox/src/linux/mod.rs b/crates/axis-sandbox/src/linux/mod.rs
index f62dabd..3a237fa 100644
--- a/crates/axis-sandbox/src/linux/mod.rs
+++ b/crates/axis-sandbox/src/linux/mod.rs
@@ -2931,15 +2931,9 @@ mod tests {
drop(claim);
// The monitor is still running; only its inherited descriptor could
- // keep the workspace locked.
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(1);
- let reclaimed = loop {
- match landlock::claim_tmpdir(workspace.path(), None) {
- Ok(claim) => break Ok(claim),
- Err(err) if std::time::Instant::now() >= deadline => break Err(err),
- Err(_) => std::thread::sleep(std::time::Duration::from_millis(10)),
- }
- };
+ // keep the workspace locked past the retry.
+ let reclaimed =
+ landlock::reclaim_tmpdir(workspace.path(), unsafe { libc::geteuid() }, false);
guard.finish();
let _ = child.kill();
let _ = child.wait();Tested on a 32-core Linux x86-64 host: the whole
The 3 remaining runs are unrelated tests in |
libtest runs cases in one process. While a claim holds an flock'd workspace fd, another test's Command::spawn forks and duplicates that fd into its child until exec+CLOEXEC. Immediate reclaim then fails as if another sandbox still held the workspace. Retry claim for up to 2s (same approach as ROCm#128). A real inherited lock from the spawned sleep still fails the deadline. Removes the wait-for-exec helper (and its clippy collapsible_if).
Motivation
url2.5.8.Test (Linux)failed on perf(windows): resume wxc-exec without scanning every thread #127, a Windows-only change, becauseclaim_tmpdir_is_free_once_only_a_spawned_command_has_descriptorsis flaky.Technical Details
urlto 2.5.9, which also needsform_urlencoded1.2.3. OnlyCargo.lockchanges.Security impact: none. No product code changes.
Test Plan
On Linux x86_64:
cargo deny,cargo audit,cargo fmt,cargo clippy, and theaxis-sandboxtests.Test Result
All pass. Not run on macOS or Windows.