xd009642 / tarpaulin

A code coverage tool for Rust projects
https://crates.io/crates/cargo-tarpaulin
Apache License 2.0
2.5k stars 180 forks source link

error: Broken pipe (os error 32) #655

Closed jeremy-rifkin closed 2 years ago

jeremy-rifkin commented 3 years ago

When I ran cargo tarpaulin -v I got a broken pipe error:

› cargo tarpaulin -v
Jan 05 16:41:24.411 DEBUG cargo_tarpaulin: set up logging
Jan 05 16:41:24.411  INFO cargo_tarpaulin::config: Creating config
Jan 05 16:41:24.442  INFO cargo_tarpaulin: Running Tarpaulin
Jan 05 16:41:24.442  INFO cargo_tarpaulin: Building project
   Compiling sorting-benchmarks v0.1.0 ( <path> )
error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
thread 'main' panicked at 'already borrowed: BorrowMutError', src/tools/cargo/src/cargo/util/config/mod.rs:307:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Jan 05 16:41:24.862 ERROR cargo_tarpaulin: Failed to compile tests! Error: an inner attribute is not permitted in this context
Error: "Failed to compile tests! Error: an inner attribute is not permitted in this context"

After running cargo clean I realized there was a build error in my code. Resolving this error allowed tarpaulin to run properly.

The issue here is 2-fold: 1) there's an unhandled non-descriptive OS error and 2) the rustc build errors aren't displayed to the user.

jeremy-rifkin commented 3 years ago

Update: The problem may be within cargo. Here's the stack trace:

stack backtrace:
   0: rust_begin_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/option.rs:1268:5
   3: cargo::core::compiler::job_queue::DrainState::drain_the_queue
   4: std::panic::catch_unwind
   5: crossbeam_utils::thread::scope
   6: cargo::core::compiler::job_queue::JobQueue::execute
   7: cargo::core::compiler::context::Context::compile
   8: cargo::ops::cargo_compile::compile_ws
   9: cargo::ops::cargo_compile::compile
  10: cargo::ops::cargo_test::compile_tests
  11: cargo::ops::cargo_test::run_tests
  12: cargo::commands::test::exec
  13: cargo::cli::main
  14: cargo::main

That being said, other cargo commands (build, run, test) provided the actual build error where cargo tarpaulin does not.

xd009642 commented 3 years ago

Yeah I've started seeing this sometimes with issues that can be solved by a clean or more fundamental project issues. I need to did more into it and find a minimal reproduction but I've been very busy with my day job recently :weary:

kkohbrok commented 3 years ago

We ran into what is probably the same error. For us it appears to fail when trying to compile tests. The error messages are the same as above. Here's a trace:

$ cargo --verbose tarpaulin
Feb 01 13:50:55.267  INFO cargo_tarpaulin::config: Creating config
Feb 01 13:50:55.430  INFO cargo_tarpaulin: Running Tarpaulin
Feb 01 13:50:55.430  INFO cargo_tarpaulin: Building project
   Compiling test_macros v0.1.0 (/home/kk/repositories/openmls/test_macros)
   Compiling openmls v0.3.0 (/home/kk/repositories/openmls)
error: could not compile `test_macros`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
thread 'main' panicked at 'already borrowed: BorrowMutError', src/tools/cargo/src/cargo/util/config/mod.rs:307:20
stack backtrace:
   0:     0x5640baed88e7 - std::backtrace_rs::backtrace::libunwind::trace::h8bc78f7bc1f75bdb
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x5640baed88e7 - std::backtrace_rs::backtrace::trace_unsynchronized::ha4c961c9576f95ba
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5640baed88e7 - std::sys_common::backtrace::_print_fmt::hc20cfdc233d6eb02
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x5640baed88e7 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h04bea14549780a0f
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x5640baeffbac - core::fmt::write::h3868db8542c90941
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/core/src/fmt/mod.rs:1096:17
   5:     0x5640baecfe32 - std::io::Write::write_fmt::h55dd75636eef6a5c
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/io/mod.rs:1568:15
   6:     0x5640baedb905 - std::sys_common::backtrace::_print::h6439e8525077c7da
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x5640baedb905 - std::sys_common::backtrace::print::h02b685f728ce3931
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x5640baedb905 - std::panicking::default_hook::{{closure}}::h7c29625065fafae1
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:208:50
   9:     0x5640baedb463 - std::panicking::default_hook::hba441710bb71f4d5
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:225:9
  10:     0x5640baedc0a1 - std::panicking::rust_panic_with_hook::ha936eb00e51bc4d9
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:591:17
  11:     0x5640baedbbe7 - std::panicking::begin_panic_handler::{{closure}}::hcd15140e0238536e
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:497:13
  12:     0x5640baed8dac - std::sys_common::backtrace::__rust_end_short_backtrace::hb13a021bb64823a1
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x5640baedbb49 - rust_begin_unwind
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:493:5
  14:     0x5640baefe291 - core::panicking::panic_fmt::h20225113c4a2f8fd
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/core/src/panicking.rs:92:14
  15:     0x5640baefe0b3 - core::option::expect_none_failed::hc6d6d4cea4fdc285
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/core/src/option.rs:1300:5
  16:     0x5640ba710c68 - cargo::core::compiler::job_queue::DrainState::drain_the_queue::h9448af63c9843ee6
  17:     0x5640ba6d9213 - std::panic::catch_unwind::hc8462636a07549c3
  18:     0x5640ba62488b - crossbeam_utils::thread::scope::h1fe7947c436372ad
  19:     0x5640ba70c65f - cargo::core::compiler::job_queue::JobQueue::execute::h209714f0746fa115
  20:     0x5640ba64decb - cargo::core::compiler::context::Context::compile::hd36e8fbd49055cf5
  21:     0x5640ba87fbae - cargo::ops::cargo_compile::compile_ws::hb31345317a1d6cb4
  22:     0x5640ba87f8fd - cargo::ops::cargo_compile::compile::h8fe1bc4431b54241
  23:     0x5640ba9239f2 - cargo::ops::cargo_test::run_tests::h4371f3ed04f093ab
  24:     0x5640ba524e44 - cargo::commands::test::exec::h11092a6f06a3e23f
  25:     0x5640ba521772 - cargo::cli::main::hb0dcf6a220434198
  26:     0x5640ba589e48 - cargo::main::h1fafcf8100afffbd
  27:     0x5640ba57b2f6 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6ab7fd8c80e69f14
  28:     0x5640ba57b31c - std::rt::lang_start::{{closure}}::h2a94ab97e0a8ec08
  29:     0x5640baedc5b7 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h7c92107c3c98a949
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/core/src/ops/function.rs:259:13
  30:     0x5640baedc5b7 - std::panicking::try::do_call::h7454c57e8fbf0cc1
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:379:40
  31:     0x5640baedc5b7 - std::panicking::try::he71cdc15ed83b5ec
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panicking.rs:343:19
  32:     0x5640baedc5b7 - std::panic::catch_unwind::hfc08ddb043e6e18c
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/panic.rs:396:14
  33:     0x5640baedc5b7 - std::rt::lang_start_internal::he4958117ec6901fd
                               at /rustc/a2f8f6281817d430e20726128b739d3c6708561c/library/std/src/rt.rs:51:25
  34:     0x5640ba58c195 - main
  35:     0x7f51ad952152 - __libc_start_main
  36:     0x5640ba515071 - <unknown>
Feb 01 13:51:10.518 ERROR cargo_tarpaulin: Failed to compile tests! Error: linking with `cc` failed: exit code: 1
Error: "Failed to compile tests! Error: linking with `cc` failed: exit code: 1"

It also happens on our CI: https://github.com/openmls/openmls/pull/328/checks?check_run_id=1805332325

xd009642 commented 3 years ago

Okay so I've improved the error message by adding the name of the target that failed before the message contents. That way you can see the crate in your project (or dependency tree) that has caused the compilation issue.

For the crate i tested it on the actual message printout was a linker error and insanely large so I figured the target name was a nice compromise between all possible error printout and enough to start diagnosing the issue

kkohbrok commented 3 years ago

I'm not very familiar with the architecture of cargo, but it seems that shell (in the cargo config) is borrowed at some point before drain_the_queue is called. I searched cargo for calls to shell, but I didn't see anything suspicious pop up. I also did a superficial search of tarpaulin, but couldn't find any calls to shell. Generally, shell seems to be borrowed only very briefly to print some message and is then dropped again. Any ideas on where else to look?

bkda commented 3 years ago

cargo clean works for me.

xd009642 commented 3 years ago

This should be fixed in the next cargo release hopefully https://github.com/rust-lang/cargo/issues/9220

xd009642 commented 2 years ago

No more reports of it so closing this issue.