Skip to content

Conversation

@batmendbar
Copy link

@batmendbar batmendbar commented Jan 7, 2026

When try_lock_exclusive succeeds, it acquires the lock. As a result, the lock is no longer available and lock_exclusive blocks indefinitely.

Description

Problem

Resolves #11137

Summary

Additional Context

User Documentation

Check one:

  • No user documentation needed.
  • Changes in docs/ included in this PR.
  • [For Experimental Features] Changes in docs/ to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

When `try_lock_exclusive` succeeds, it acquires the lock. As a result, the lock is no longer available and `lock_exclusive` blocks indefinitely.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

@aakoshh
Copy link
Contributor

aakoshh commented Jan 8, 2026

Thank you for opening this PR.

Have you actually encountered a deadlock due to this issue? Can you create a bug ticket to replicate it?

When try_lock_exclusive succeeds, it acquires the lock. As a result, the lock is no longer available and lock_exclusive blocks indefinitely.

If this were true, we should get this problem every time we try to compile anything. I assume that the way it should work is that if the same process or thread calls lock_exclusive on the same file again, then it won't block itself.

I tried changing it the following way, and it still worked:

        println!("locking {lock_name}...");
        fs2::FileExt::try_lock_exclusive(&file)?;
        fs2::FileExt::lock_exclusive(&file)?;
        fs2::FileExt::try_lock_exclusive(&file)?;
        fs2::FileExt::lock_exclusive(&file)?;
        println!("locked {lock_name}");

@batmendbar
Copy link
Author

batmendbar commented Jan 9, 2026

Have you actually encountered a deadlock due to this issue?

I encountered a deadlock when running it on a Windows machine. It was previously working fine on my Mac machine. I assume operating systems have different strictness for acquiring the lock again.

@aakoshh
Copy link
Contributor

aakoshh commented Jan 9, 2026

Ah, right, thank you for creating the ticket, that gives more context, great to know that it didn't work on Windows.

Do you mind updating the PR to handle all cases?

@batmendbar
Copy link
Author

Updated the PR to handle all cases

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for fixing all of them 🙏

@aakoshh aakoshh requested a review from asterite January 14, 2026 21:15
Copy link
Collaborator

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@aakoshh
Copy link
Contributor

aakoshh commented Jan 15, 2026

I don't know if you saw the error, but clippy would like to remove a layer of branching:

error: this `else { if .. }` block can be collapsed
   --> tooling/nargo_cli/src/cli/mod.rs:293:16
    |
293 |           } else {
    |  ________________^
294 | |             if fs2::FileExt::try_lock_shared(&file).is_err() {
295 | |                 eprintln!("Waiting for lock on {path_display}...");
296 | |                 fs2::FileExt::lock_shared(&file)
...   |
299 | |         }
    | |_________^

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.

Hanging lock logic

3 participants