Files
codex/codex-rs/rollout/src/maintenance_tests.rs
T
goodman-oai 12b2b58e63 Release the rollout maintenance lock when its guard is dropped (#57247)
## Why

A duplicated or inherited file handle can keep the rollout maintenance lock held after its guard is dropped, blocking subsequent compression or migration.

## What changed

Explicitly unlock the file in `RolloutMaintenanceGuard::drop` so lock ownership ends with the guard even if another handle remains open.

## Testing

Add a regression test that retains a duplicated file handle, verifies that the lock stays held until the last shared guard is dropped, and checks that dropping the old handle does not release a newly acquired lock.

GitOrigin-RevId: 19005680dbc0a01b36c6f13e4ec358c6f00b75a0
2026-10-26 20:52:45 +00:00

33 lines
1.1 KiB
Rust

//! Tests maintenance ownership across shared guards and duplicated file handles.
use std::io;
use std::sync::Arc;
use tempfile::TempDir;
use super::try_acquire_rollout_maintenance_lock;
#[test]
fn dropping_last_guard_releases_lock_with_duplicated_handle() -> io::Result<()> {
let home = TempDir::new()?;
let guard = Arc::new(
try_acquire_rollout_maintenance_lock(home.path())?.expect("acquire maintenance lock"),
);
let retained_guard = Arc::clone(&guard);
let duplicated_file = guard.file.try_clone()?;
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
drop(guard);
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
drop(retained_guard);
let next_guard = try_acquire_rollout_maintenance_lock(home.path())?
.expect("dropping the last guard releases the lock despite the duplicated handle");
drop(duplicated_file);
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
drop(next_guard);
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_some());
Ok(())
}