Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failures executing Cargo concurrently using a local registry #6588

Closed
hugwijst opened this issue Jan 22, 2019 · 2 comments · Fixed by #6591
Closed

Build failures executing Cargo concurrently using a local registry #6588

hugwijst opened this issue Jan 22, 2019 · 2 comments · Fixed by #6591
Labels
C-bug Category: bug

Comments

@hugwijst
Copy link
Contributor

Problem

There is a race condition when building multiple projects concurrently that depend on the same crates. When extracting crates from a local registry, the crate is opened as read-only with shared locks (https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/local.rs#L74). Unpacking the crate is assumed to be safe due to the tar file being locked (https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/mod.rs#L428).

Output of build failure:

   Unpacking form v0.4.0 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking svd2rust v0.14.0 (registry `file:///home/builduser/cargo_registry/latest`)
  Installing svd2rust v0.14.0
  Installing form v0.4.0
   Unpacking log v0.4.6 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking cast v0.2.2 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking getopts v0.2.18 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking svd-parser v0.6.0 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking failure v0.1.3 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking quote v0.3.15 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking env_logger v0.5.13 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking clap v2.32.0 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking syn v0.11.11 (registry `file:///home/builduser/cargo_registry/latest`)
   Unpacking syn v0.11.11 (registry `file:///home/builduser/cargo_registry/latest`)
error: failed to compile `form v0.4.0`, intermediate artifacts can be found at `/tmp/cargo-installKeMHuZ`

Caused by:
  unable to get packages from source

Caused by:
  failed to download replaced source registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to unpack package `syn v0.11.11 (registry `file:///home/builduser/cargo_registry/latest`)`

Caused by:
  failed to unpack entry at `syn-0.11.11/src/aster/mod.rs`

Caused by:
  failed to unpack `/home/builduser/.cargo/registry/src/-39fe0c9a09214cd4/syn-0.11.11/src/aster/mod.rs`

Steps

  1. Create a local registry.
  2. Clear the local crate source cache.
  3. Execute two builds at the same time.

Possible Solution(s)

  • Lock the crate file on the local registry. This is not ideal, as the local registry might be read-only or an NFS mount.
  • Copy the crate file to the registry cache in $CARGO_HOME, exclusively locking that copy.
  • Locking an empty file in $CARGO_HOME.

Notes

Output of cargo version:
cargo 1.29.0 (524a578d7 2018-08-05)

@hugwijst hugwijst added the C-bug Category: bug label Jan 22, 2019
@alexcrichton
Copy link
Member

Thanks for the report, definitely seems like a bug! We'll want to handle this by acquiring a read-write lock on the destination we're writing into. If we're extracting a tarball we're already writing files there and we rely on the atomicity of the destination, not the source.

In theory shouldn't be too hard to do internally in Cargo!

@hugwijst
Copy link
Contributor Author

Do you prefer copying the crate file or locking an empty file? I might have some time today to create a PR.

hugwijst added a commit to hugwijst/cargo that referenced this issue Jan 23, 2019
Copy crate and keep exclusive lock to it with local registries. Ensures
that only one instance will try to extract the source of a new package.

Fixes rust-lang#6588.
bors added a commit that referenced this issue Jan 29, 2019
Fix race condition in local registry crate unpacking

Copy crate and keep exclusive lock to it with local registries. Ensures
that only one instance will try to extract the source of a new package.

Fixes #6588.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants