Skip to content

cargo-wdk integration tests fail intermittently when Rust Analyzer is enabled (cargo clean can’t delete build-script) #607

@svasista-ms

Description

@svasista-ms

Summary

When Rust Analyzer (VS Code) is enabled for the cargo-wdk test fixture projects, cargo-wdk integration tests intermittently fail. The failure happens during a cargo clean step inside the test flow: Cargo cannot remove a generated build-script executable because it’s locked by another process. This reproduces on main. This looks like a Windows file-locking / concurrent-cargo access issue between the test runner and Rust Analyzer’s background cargo invocations. However, incorrect locking when build and artifact directories are same were fixed in upstream in cargo.

Environment

OS: Windows 11
VS Code: 1.108.1
rust-analyzer extension: Version 0.3.2761, Server Version 0.3.2761-standalone (080e70378c 2026-01-18)
Toolchain (latest stable where reproduced):

cargo 1.92.0 (344c4567c 2025-10-21)
rustc 1.92.0 (ded5c06cf 2025-12-08)

Repro steps

  1. Open the repo in VS Code with Rust Analyzer enabled.
  2. Ensure Rust Analyzer is enabled for the test fixture projects under crates/cargo-wdk/tests
  3. Run the integration test repeatedly until it fails:

cargo test -p cargo-wdk --test build_command_test -- --nocapture

  1. Eventually, the test fails with an error from cargo clean indicating it cannot delete a build-script executable (Windows “file in use” / access denied).

Integration tests should be reliable regardless of Rust Analyzer being enabled in VS Code. Even if tests serialize per-fixture work (mutex keyed by fixture path), Rust Analyzer is an external concurrent actor and can still race the fixture directory.

Suspected scenario: Rust Analyzer triggers background cargo operations (check/build/build-scripts) in the same fixture directories while tests run cargo clean, leaving an open handle on a build-script exe.

ProcMon capture filtered to the locked build-script-build.exe or Output from Sysinternals handle.exe at the moment of failure to identify which process holds the file lock (likely rust-analyzer, cargo, rustc, or code.exe) are useful diagnostics that can help resolve this issue.

Originally posted by @svasista-ms in #494 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions