Skip to content

Conversation

@sabine
Copy link
Contributor

@sabine sabine commented Nov 6, 2025

Resolves #12685

  • Emit a warning when dune needs to wait for the build directory lock held by
    another process
  • Include the PID of the lock-holding process when available
  • Provide actionable guidance on removing stale lock files

Example output:

Warning: Build directory is locked by another dune process (pid: 12345). Waiting
for the lock to be released...
If this process is no longer running, delete the lock file: _build/.lock

@Alizter Alizter requested a review from ElectreAAS November 6, 2025 13:59
Copy link
Member

@shonfeder shonfeder left a comment

Choose a reason for hiding this comment

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

This looks like a nice fix to me!

From the CI, it looks like the tests to be updated.

Comment on lines 93 to 112
let emit_lock_warning lock_held_by =
let pid_suffix =
match lock_held_by with
| Lock_held_by.Unknown -> ""
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid
in
let condition =
match lock_held_by with
| Pid_from_lockfile _ -> "If this process is no longer running"
| Unknown -> "If no other dune process is running"
in
User_warning.emit
[ Pp.textf
"Build directory is locked by another dune process%s. Waiting for the lock to be \
released..."
pid_suffix
; Pp.textf "%s, delete the lock file: %s" condition (Path.Build.to_string lock_file)
]
;;

Copy link
Member

Choose a reason for hiding this comment

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

This looks like a really nicely reasoned out error message to me. 👌

| `Success -> `Stop
| `Failure -> `Continue)
| `Failure ->
if not !warned
Copy link
Member

Choose a reason for hiding this comment

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

It was not obvious to me how warned could ever be true. I guess it is because with_timeout will try this operation repeatedly? If that's the reason, I think a short comment explaining this when the ref is created on line 129 could be helpful.

@shonfeder
Copy link
Member

@sabine could you update the tests here, so we can land the PR?

Copy link
Collaborator

@ElectreAAS ElectreAAS left a comment

Choose a reason for hiding this comment

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

Following the test failures will make this easier to understand, but the current behaviour is incorrect.
If one runs a server dune build -w and a client dune build @foo, they will receive the warning about "waiting for the lock" even where there is no waiting involved, and the build request is being served correctly.

When dune attempts to forward a build request to an existing dune process
but cannot establish an RPC connection, it silently retries indefinitely.
This adds a warning message to inform users what is happening and how to
resolve the issue by deleting _build/.lock if no other dune process is
actually running.

Signed-off-by: Sabine Schmaltz <[email protected]>
@sabine sabine force-pushed the no_more_silently_hanging_on_acquire_lock branch from a4f217a to 3e24f22 Compare November 20, 2025 17:16
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.

Dune silently hangs when build directory is locked by another process

3 participants