Repository navigation
test(remove): retry the drain when a forked child still holds the trash lock - #4530
Conversation
…sh lock drain_trash_deletes_staged_entries_once_the_lock_is_free failed in the nightly feature-powerset job. A child that a concurrent test forks while the test holds the trash lock inherits the flock until it execs, so the drain after the release can still find the lock held and exit as designed, leaving the staged entry. Retry the drain until the entries are gone, bounded at 10s.
worktrunk-bot
left a comment
There was a problem hiding this comment.
test_configure_shell_opens_rc_with_exclusive_lock in src/commands/configure_shell.rs has the same race. It holds an fs2 flock and drops it, then calls contender.try_lock_exclusive().unwrap() once. A child that a concurrent test forks while locked is open inherits the lock and keeps it until it execs, so that unwrap can panic. I'll push the same deadline retry there so both tests are fixed in this PR.
…lds it Same fork-inherits-flock race as the trash drain test: a child forked by a concurrent test while the lock is held keeps it until exec, so the first try_lock_exclusive after release can fail.
…twice Windows LockFileEx is not reentrant, so a second try_lock_exclusive after the loop's successful one fails.
…lper Both lock-release tests now poll through testing::wait_for, which the test conventions name for eventual conditions. It stops at the first successful attempt, so the Windows relock can't collide with a lock the handle already holds, and it leaves no uncovered retry body in either test.
|
The same race recurred on |
|
The race failed |
The `feature-powerset` check on #4597 failed because `background_removal_preserves_native_path_arguments` expected staged trash to be empty immediately after removal. A concurrently forked child can briefly inherit the trash drain lock, so the test's one cleanup attempt may leave the staged entry behind. The test now uses the bounded `wait_for` helper to retry cleanup and still verifies the checkout and registration are removed. This follows the same accepted fix for another drain test in #4530. The [failed feature powerset job](https://github.com/max-sixty/worktrunk/actions/runs/40644576267/job/122670315541) exercised the original assertion. The targeted test passes locally after the change. The full `cargo run -- hook pre-merge --yes` gate ran 5,463 tests and reported seven failures outside this test; some require socket operations unavailable in this sandbox. CI on this PR will provide the complete verification. Co-authored-by: worktrunk-bot <[email protected]>
The nightly
feature-powersetjob failed ingit::remove::tests::drain_trash_deletes_staged_entries_once_the_lock_is_free(added in #4516) withassertion failed: staged_trash_entries(&trash).is_empty(). This is a race in the test, not a bug in the drain. After the test drops its lock holder, it expects the nextdrain_trashto get the lock. But another test in the same process can fork a child while the holder is open. That child inherits the descriptor, and the flock stays held until it execs. The drain seesWouldBlockand exits, leaving the deletion to the holder, as designed.test_configure_shell_opens_rc_with_exclusive_lockhas the same race on the rc-file lock.Both tests now wait for the release through the shared
testing::wait_forhelper. It polls with a bounded timeout and stops at the first success, so on Windows the test never asks a handle that already holds the lock to take it again.Verification: I reproduced the race with a scratch test that ran the same lock/release/drain sequence 2000 times while four threads spawned
truein a loop. The first drain left the entry behind in 17–20 of the 2000 iterations. With the retry, no iteration left it. Both tests pass locally, and clippy is clean.The same window exists in production, but it only delays cleanup: a staged entry waits in the trash until the next removal's drain. The doc comment on
trash_drain_runningalready accepts a similar window, so this PR doesn't change the drain itself.Refs #4509