Cargo build stuck: "Blocking waiting for file lock" — how to fix

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: when Rust compilation turns into a quest

\n\n

You decided to build Parity (or any other complex Rust project) from source. The cargo build command is running, the terminal is silent, and after a minute you see a message familiar to many:

\n\n
Blocking waiting for file lock on the registry index
\n\n

The build hangs completely. Ctrl+C doesn't help, restarting the terminal doesn't either. Sound familiar? This problem is one of the most popular on Stack Overflow (thousands of views), and today we'll break it down to the smallest detail.

\n\n

In this article, as your guide to the world of Rust, I will tell you:
\n- Why does this error occur?
\n- How to fix it in 30 seconds?
\n- How to prevent it from happening altogether?
\n- And we'll take a little look under the hood of Cargo.

\n\n

Let's go! 🚀

\n\n

Where does "Blocking waiting for file lock on the registry index" come from?

\n\n

First, let's translate this error from Cargo language into human language:

\n\n

"I, Cargo, want to download or update the package list from the registry, but I can't — the lock file is already held by another process. Waiting..."

\n\n

In the Rust ecosystem, cargo uses file locks (.lock files) to prevent two processes from trying to write to the registry cache (~/.cargo/registry) at the same time. This protects against data corruption, but sometimes the lock "sticks".

\n\n

Main causes of the hang

\n
    \n
  • Abnormal termination of a previous build — you closed the terminal, the computer shut down, or cargo build crashed with an error, but the lock file remained.
  • \n
  • Two instances of Cargo in the same project — started a build in two terminal windows simultaneously.
  • \n
  • Building Parity from source — this project pulls in a huge number of dependencies (hundreds of crates), and Cargo can hang during the indexing phase, especially on weak machines or with a slow internet connection.
  • \n
  • Permission issues — rare, but can happen when ~/.cargo belongs to another user.
  • \n
  • File system without lock support — for example, some network shares or WSL without proper configuration.
  • \n
\n\n

5 methods of solution (from quick to reliable)

\n\n

🔧 Method 1: Kill the Cargo process (fastest)

\n

If you are sure that no other build is running, simply terminate the process holding the lock.

\n\n

Linux/macOS:

\n
pkill cargo\n# or more forcefully:\nkillall -9 cargo
\n\n

Windows (PowerShell):

\n
Get-Process cargo | Stop-Process -Force
\n\n

After that, run cargo build again. In 80% of cases, this is enough.

\n\n

🔧 Method 2: Manually delete the lock file

\n

If the first method didn't help, go to the registry directory and delete the lock file.

\n\n

Path:

\n
# Linux/macOS\nrm -f ~/.cargo/registry/.cache-lock\nrm -f ~/.cargo/registry/.package-cache\n\n# Windows (cmd)\ndel %USERPROFILE%\\.cargo\\registry\\.cache-lock\ndel %USERPROFILE%\\.cargo\\registry\\.package-cache
\n\n

After this, Cargo will create a new lock file on the next run. Important: make sure no other Cargo processes are running, otherwise you risk damaging the cache.

\n\n

🔧 Method 3: Cargo clean — the nuclear option

\n

If nothing helps, clear everything that has accumulated. This will delete the target folder and reset the dependency cache for the current project. The next build will take longer, but it will be clean.

\n\n
cargo clean
\n\n

After that, try building the project again:

\n
cargo build
\n\n

This method is especially useful if you were building Parity or another project with a huge dependency tree.

Blogs

Book Recommendations