Skip to content

Concurrency issue: Running vp install in parallel across multiple directories fails on Windows #1465

@rorychatt

Description

@rorychatt

When attempting to run vp install concurrently in multiple subdirectories, the command frequently fails with an exit code of 1. This is commonly encountered in monorepos or when using build systems like MSBuild that attempt to build multiple frontend projects in parallel.

Steps to Reproduce:

  1. Create multiple frontend directories (e.g. frontend-a, frontend-b, frontend-c) initialized with vite-plus.
  2. On a Windows machine, trigger vp install inside all of these directories at the exact same time (for example, via parallel MSBuild targets or using a tool like concurrently).
  3. Observe that one or more of the instances will crash/fail, returning exit code 1.

Expected Behavior:
vp install should be safe to execute concurrently in multiple directories, gracefully handling any internal npm/pnpm cache locking or global store access without crashing.

Current Workaround:
We are currently wrapping vp install and vp build in a global OS-level Mutex during our build process to force sequential execution and avoid the race condition.

Environment:

  • OS: Windows
  • Package Manager: pnpm (via vp wrapper)
  • Vite Plus version: 0.1.19

Proposed fix

To fix this cross-platform, vite-plus needs to open the lock file without truncating it, using OpenOptions:

use std::fs::OpenOptions;

let lock_path = parent_dir.join(format!("{version}.lock"));
let lock_file = OpenOptions::new()
    .read(true)
    .write(true)
    .create(true)
    .truncate(false) // CRITICAL: Do not truncate, which conflicts with locked files on Windows
    .open(lock_path.as_path())?;

lock_file.lock()?;

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions