Skip to content

flock tests: cover the case of asking for both locks on the same file handle#5073

Merged
RalfJung merged 1 commit into
rust-lang:masterfrom
RalfJung:flock-tests
May 28, 2026
Merged

flock tests: cover the case of asking for both locks on the same file handle#5073
RalfJung merged 1 commit into
rust-lang:masterfrom
RalfJung:flock-tests

Conversation

@RalfJung
Copy link
Copy Markdown
Member

No description provided.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 28, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label May 28, 2026
@RalfJung RalfJung marked this pull request as draft May 28, 2026 07:31
@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels May 28, 2026
@RalfJung RalfJung marked this pull request as ready for review May 28, 2026 08:27
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 28, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels May 28, 2026
@RalfJung RalfJung enabled auto-merge May 28, 2026 08:28
@RalfJung RalfJung changed the title flock tests: cover the case of asking for both locks on the same file flock tests: cover the case of asking for both locks on the same file handle May 28, 2026
@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented May 28, 2026

Strange, I would have expected this to work on Windows

    // Test that we can apply many shared locks
    file1.lock_shared().unwrap();
    file2.lock_shared().unwrap();
    // Test that shared lock prevents exclusive lock
    assert!(matches!(file1.try_lock().unwrap_err(), fs::TryLockError::WouldBlock));
    // Unlock one shared lock.
    file2.unlock().unwrap();
    // Now just file1 has a shared lock -- and we can convert that to an exclusive lock.
    file1.try_lock().unwrap(); // <-- fails here

But it seems like somehow releasing the lock on file2 does not actually make the lock available for file1? @ChrisDenton any idea what might be happening?

@ChrisDenton
Copy link
Copy Markdown
Member

Oh right, sorry, it's just the exclusive lock then shared lock case that works. Doing the opposite doesn't.

A shared lock can overlap an exclusive lock if both locks were created using the same file handle.

@RalfJung
Copy link
Copy Markdown
Member Author

Wow that's... creative. Thanks for clarifying.

@RalfJung RalfJung force-pushed the flock-tests branch 3 times, most recently from a84f61f to 8dd6005 Compare May 28, 2026 09:37
@RalfJung
Copy link
Copy Markdown
Member Author

FWIW I'd argue both locks were "created using the same file handle" in that example... they are both created via file1.

@RalfJung RalfJung force-pushed the flock-tests branch 2 times, most recently from f3bcce4 to de37cc7 Compare May 28, 2026 09:43
@RalfJung RalfJung disabled auto-merge May 28, 2026 09:43
@RalfJung RalfJung force-pushed the flock-tests branch 2 times, most recently from d6b283a to a3bbcbf Compare May 28, 2026 10:11
@RalfJung RalfJung enabled auto-merge May 28, 2026 10:32
@RalfJung RalfJung added this pull request to the merge queue May 28, 2026
Merged via the queue into rust-lang:master with commit 1cf48e9 May 28, 2026
13 checks passed
@RalfJung RalfJung deleted the flock-tests branch May 28, 2026 11:43
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants