Skip to content

Race condition with bins & examples having the same name #751

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

Closed
tomassedovic opened this issue Oct 23, 2014 · 0 comments · Fixed by #758
Closed

Race condition with bins & examples having the same name #751

tomassedovic opened this issue Oct 23, 2014 · 0 comments · Fixed by #758

Comments

@tomassedovic
Copy link
Contributor

Cargo has a race condition when a bin and an example have the same name (it's possible there's more when you add tests and benches into the mix, but I haven't checked).

Since the final exacutables and their intermediate build artifacts end up with the same path, if they're built in parallel (e.g. with cargo test), things get weird.

This could be fixed in multiple ways (separate directories, unique temporary paths, locking), but maybe we can just require that each binary have a unique name? Looking at Cargo codebase itself, that seems to be the convention anyway.

Here's how to reproduce the issue:

Create a project with a bin and example named foo:

cargo new racer
cd racer
mkdir -p src/bin
echo 'fn main() { println!("this is a bin"); }' > src/bin/foo.rs
mkdir -p examples
echo 'fn main() { println!("this is an example"); }' > examples/foo.rs

Now run cargo test multiple times (make sure you delete the target dir between each run). You'll randomly get one of the outputs below. If you pass -j 1, the output is consistent and without errors (but one of the executables gets overwritten by the other one).

  1. ICE
$ rm -rf target && cargo test -v
   Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'called `Result::unwrap()` on an `Err` value: couldn't copy path (the source path is not an existing file; from=/home/thomas/tmp/racer/target/foo.0.o; to=/home/thomas/tmp/racer/target/foo.o)', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/result.rs:808


Build failed, waiting for other jobs to finish...
Could not compile `racer`.

Caused by:
  Process didn't exit successfully: `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib` (status=101)
  1. Failed test compilation with an unlink path error:
$ rm -rf target && cargo test -v
   Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: failed to remove /home/thomas/tmp/racer/target/foo.0.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.0.o)
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `racer`.

Caused by:
  Process didn't exit successfully: `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib` (status=101)
  1. Successful test run with an unlink path error:
$ rm -rf target && cargo test -v
   Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
     Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: failed to remove /home/thomas/tmp/racer/target/foo.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.o)
error: failed to remove /home/thomas/tmp/racer/target/foo.metadata.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.metadata.o)
     Running `/home/thomas/tmp/racer/target/foo-f183869c62948094`

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

     Running `/home/thomas/tmp/racer/target/racer-3fa6c9bb6b4c36ba`

running 1 test
test it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests racer
     Running `rustdoc --test /home/thomas/tmp/racer/src/lib.rs --crate-name racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

This seems vaguely related to issue #354.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Oct 27, 2014
This ends up killing two birds with one stone! The rationale behind this is that
the example and bin namespaces are not the same, and we don't mix metadata into
either filename, so the outputs need to be in different locations.

Closes rust-lang#193
Closes rust-lang#751
bors added a commit that referenced this issue Oct 27, 2014
This ends up killing two birds with one stone! The rationale behind this is that
the example and bin namespaces are not the same, and we don't mix metadata into
either filename, so the outputs need to be in different locations.

Closes #193
Closes #751
@bors bors closed this as completed in #758 Oct 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant