Skip to content

Remove the Global Build Lock #12731

@joelreymont

Description

@joelreymont

Issue #12731: Remove the Global Build Lock

Current Behavior

Dune uses a global build_system_mutex that serializes all build requests. When watch mode holds this lock, RPC requests wait for the lock to be released before executing.

Observed Problem

When a developer runs dune build --watch and an IDE sends an RPC request (e.g., for type information), the RPC request waits for the watch mode build to complete before starting execution.

Example timeline:

  • 00:00 - Watch mode acquires lock, starts build
  • 00:02 - RPC request arrives, waits for lock
  • 00:05 - Watch mode releases lock
  • 00:05 - RPC request acquires lock, executes

The RPC request waits 3 seconds in this scenario.

Proposed Change

Remove the global build_system_mutex and replace it with a build coordinator that allows multiple build sessions to execute concurrently.

Implementation Details

See PR #12730 for implementation.

Correctness Mechanisms

Existing mechanisms that prevent race conditions:

  • Path locks prevent concurrent writes to the same file
  • Memo system provides first-write-wins semantics for rule execution
  • Atomic file operations remain unchanged

Progress Tracking

Progress tracking moved to Build_coordinator to prevent duplicate counting when multiple sessions build shared rules via Memo.

Promotion and Pending Targets

Centralized promotion queue with deduplication (first registration wins).
Reference-counted pending target tracking (file deleted when count reaches zero).

Testing Limitation

Cram tests execute sequentially and cannot verify concurrent execution. Manual testing required for:

  • Watch mode + concurrent RPC requests
  • Multiple RPC clients
  • IDE integration with watch mode

Use Case

Primary use case: IDE responsiveness during watch mode builds. When dune build --watch is running and an LSP request arrives, the request can execute without waiting for the watch build to complete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalRFC's that are awaiting discussion to be accepted or rejectedrequires-team-discussionThis topic requires a team discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions