Nightly: an ended session unlocks its lease

A nightly session's lease is a file lock, which the system frees only
when every copy of its handle is closed or the lock is unlocked. A
child process that any thread starts holds a copy of every handle until
it runs its program. When a session ended during that time, by its
controlled return or by the caught panic that frees the lease for the
successor a graphics restart starts, the next launch found the lease
held and kept no session record. Under cargo test, three
nightly_session tests failed this way while the installed-root test
started its child process.

Session now unlocks the lease when it is dropped. A new test holds a
copy of the lease's handle while a session completes and while one is
dropped, and the next session takes the lease each time.
This commit is contained in:
dotCooCoo committed 2026-11-27 16:46:36 -08:00
1 parent 51302b2de0
commit 37567e8c5a
1 file changed
+24
+24
View File
@@ -22,6 +22,15 @@ pub struct Session {
previous_unclean: bool,
}
impl Drop for Session {
/// Frees the lease when the session ends. A child process that any thread starts holds a copy of
/// the lease's handle until it runs its program, and the lock is only freed by closing every copy
/// or by unlocking.
fn drop(&mut self) {
let _ = self._lease.unlock();
}
}
fn regular_or_missing(path: &Path) -> io::Result<bool> {
match std::fs::symlink_metadata(path) {
Ok(metadata) if metadata.file_type().is_file() && !metadata.file_type().is_symlink() => Ok(true),
@@ -258,6 +267,21 @@ mod tests {
assert!(!fixture.0.join(RECORD).exists(), "a controlled return clears its record");
}
#[test]
fn an_ended_session_frees_the_lease_while_a_copy_of_its_handle_is_open() {
let fixture = Fixture::new();
let first = Session::begin(Some(&fixture.0), "first", None).unwrap().unwrap();
// A child process that is starting holds such a copy.
let first_copy = first._lease.try_clone().unwrap();
first.complete().unwrap();
let second = Session::begin(Some(&fixture.0), "second", None).unwrap();
assert!(second.is_some(), "a completed session frees the lease");
let second_copy = second.as_ref().map(|session| session._lease.try_clone().unwrap());
drop(second);
assert!(Session::begin(Some(&fixture.0), "third", None).unwrap().is_some(), "a dropped session frees the lease");
drop((first_copy, second_copy));
}
#[test]
fn cleanup_never_removes_an_unknown_changed_record() {
let fixture = Fixture::new();