Skip to content

Stronger locking for parallel operations #13883

@konstin

Description

@konstin

We need to ensure that there a no race conditions when two uv subcommands in parallel. This includes:

  • Parallel filesystem modifications in interpreters/venvs
  • TOCTOU differences between determining packages and performing changes
  • Installing as well as parallel editing of pyproject.toml, including TOCTOU errors with

We already enforce these guarantees with locks for most subcommands. (Follow-up to #12751.)

The required locking generally applies to operations of the same kind, such as uv sync, but it can also be cross-operation, e.g. uv pip list could fail reading the installed packages if uv sync removes some mid-operation.

An exception is the cache, where we use symlinks for atomic operations to allow safe parallel modification. If we need multiple locks, e.g. pyproject.toml and the interpreter, we should define and document an order for the locks and use it globally to prevent deadlocks.

Important

Less Important

  • Determine if there are reliable testing strategies, when uv testing currently uses subprocesses.
    Integrating shuttle is not feasible with several uv processes, but maybe a script that locally runs all modifying uv subcommands in a loop in parallel and verifies that we en in a sound state?
  • uv add, uv remove and uv version --bump should lock pyproject.toml before computing edits.
    The use case here is that these operations may be started by an IDE/LSP while another operation is e.g. still in its sync phase and/or may roll back in the end.
    We can likely test this by having a build we control in the sync phase.
  • uv add and uv remove should not lock a global interpreter path when they're not actually going to sync anything (e.g. inline script metadata without an existing cached or locked venv)

Nice to have

  • Are there portable filesystem read-write locks to allow e.g. blocking uv pip list from reading while uv sync is editing?
  • Does uv init/uv venv and venv creation in general need to lock?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement to existing functionalityinternalA refactor or improvement that is not user-facing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions