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

error: incremental compilation: could not create session directory lock file: Input/output error (os error 5) #76251

Closed
allenzhao64 opened this issue Sep 2, 2020 · 3 comments
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. P-medium Medium priority

Comments

@allenzhao64
Copy link

allenzhao64 commented Sep 2, 2020

I tried this code:

$ cargo build
error: incremental compilation: could not create session directory lock file: Input/output error (os error 5)

thread 'rustc' panicked at 'trying to get session directory from `IncrCompSession`: NotInitialized', src/librustc_session/session.rs:840:48
stack backtrace:
   Compiling term v0.6.1
   Compiling rand v0.6.5
   0:     0x7f53f5fcd0d5 - backtrace::backtrace::libunwind::trace::h396c07d2071b43af
                               at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7f53f5fcd0d5 - backtrace::backtrace::trace_unsynchronized::h7aa0e4bb23d9c158
                               at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7f53f5fcd0d5 - std::sys_common::backtrace::_print_fmt::hd15ac5d4adcd355b
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7f53f5fcd0d5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hec5354be8ccc3ecc
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7f53f600a7ec - core::fmt::write::h3d34909eeb4f225b
                               at src/libcore/fmt/mod.rs:1076
   5:     0x7f53f5fbf7e3 - std::io::Write::write_fmt::h1da287b3de55ed16
                               at src/libstd/io/mod.rs:1537
   6:     0x7f53f5fd20f0 - std::sys_common::backtrace::_print::h4d206838e1ace354
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7f53f5fd20f0 - std::sys_common::backtrace::print::h1f778e9940ee5977
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7f53f5fd20f0 - std::panicking::default_hook::{{closure}}::h704403a56cbf5783
                               at src/libstd/panicking.rs:198
   9:     0x7f53f5fd1e3c - std::panicking::default_hook::ha4567a10dec4ef8d
                               at src/libstd/panicking.rs:218
  10:     0x7f53f66fc5c3 - rustc_driver::report_ice::h162d93c732cfa263
  11:     0x7f53f5fd279c - std::panicking::rust_panic_with_hook::h88a1f16ec8a7bb20
                               at src/libstd/panicking.rs:490
  12:     0x7f53f5fd237b - rust_begin_unwind
                               at src/libstd/panicking.rs:388
  13:     0x7f53f5fd22eb - std::panicking::begin_panic_fmt::ha3ac96e620978458
                               at src/libstd/panicking.rs:342
  14:     0x7f53f91d81d3 - rustc_session::session::Session::incr_comp_session_dir::h15dc136056f816e8
  15:     0x7f53f7f768e2 - rustc_incremental::persist::fs::garbage_collect_session_directories::hc4ddf55a33fd9839
  16:     0x7f53f690dc10 - rustc_session::utils::<impl rustc_session::session::Session>::time::h559d22a69e3f6c89
  17:     0x7f53f68af60d - rustc_interface::queries::Queries::register_plugins::h618f60f3b86c029d
  18:     0x7f53f66c01f8 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h71a70a633e2a927e
  19:     0x7f53f670b3bf - rustc_ast::attr::with_globals::hb004aafbc16d2612
  20:     0x7f53f671040e - std::sys_common::backtrace::__rust_begin_short_backtrace::h547683b640c7a8c7
  21:     0x7f53f66c3c2e - core::ops::function::FnOnce::call_once{{vtable.shim}}::hcb850442add305d8
  22:     0x7f53f5fe20fa - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hcf205bcf9b46c587
                               at /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/liballoc/boxed.rs:1076
  23:     0x7f53f5fe20fa - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h2d53e2246128f5d8
                               at /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/liballoc/boxed.rs:1076
  24:     0x7f53f5fe20fa - std::sys::unix::thread::Thread::new::thread_start::h3b6d8a0cd87a87c6
                               at src/libstd/sys/unix/thread.rs:87
  25:     0x7f53f5d49aa1 - start_thread
  26:     0x7f53f568aaad - __clone
  27:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0 (5c1f21c3b 2020-07-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

Meta

rustc --version --verbose:

linux-2018.gtisoft.com:/Ydir/savesets/v2022/g/lib/gtchannel/gtchannel_core # rustc --version --verbose
rustc 1.45.0 (5c1f21c3b 2020-07-13)
binary: rustc
commit-hash: 5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2
commit-date: 2020-07-13
host: x86_64-unknown-linux-gnu
release: 1.45.0
LLVM version: 10.0

Backtrace

<backtrace>

@allenzhao64 allenzhao64 added the C-bug Category: This is a bug. label Sep 2, 2020
@jyn514 jyn514 added the A-incr-comp Area: Incremental compilation label Sep 2, 2020
@allenzhao64
Copy link
Author

some other observation:

The cargo build works only when using a local device path.

cargo build --release works fine,

The file is hosted on a NFS device

@ms140569
Copy link

ms140569 commented Dec 29, 2020

I'm facing this issue when compiling anything hosted on my SAMBA/SMB Fileserver (rather than NFS)

This is:
Mac OSX 10.14.6
rustc 1.48.0 (7eac88a 2020-11-16)

my workaround is to either disable incremental compilation or work on a local APFS Filesystem ...

Stacktrace below:

   Compiling cynon v0.0.1 (/Volumes/server/data/Matthias/prj/rust/cynon)
     Running `rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=f8228d0fe8773068 -C extra-filename=-f8228d0fe8773068 --out-dir /Volumes/server/data/Matthias/prj/rust/cynon/target/debug/build/cynon-f8228d0fe8773068 -C incremental=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/incremental -L dependency=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/deps --extern prost_build=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/deps/libprost_build-0de83129d3e4f190.rlib`
error: incremental compilation: could not create session directory lock file: Operation not supported (os error 45)

thread 'rustc' panicked at 'trying to get session directory from `IncrCompSession`: NotInitialized', compiler/rustc_session/src/session.rs:874:48
stack backtrace:
   0:        0x10981baa4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcfc48256a5ab8835
   1:        0x109882590 - core::fmt::write::haf3903118f694c48
   2:        0x10980d0a6 - std::io::Write::write_fmt::h7385463ac87804ed
   3:        0x10982046f - std::panicking::default_hook::{{closure}}::h91bd4c58cf71392b
   4:        0x10982013d - std::panicking::default_hook::h7bd29c87df967048
   5:        0x10eb0bc73 - rustc_driver::report_ice::h36110b17656cf994
   6:        0x109820b9e - std::panicking::rust_panic_with_hook::hae2b05f08a320721
   7:        0x1098206fb - std::panicking::begin_panic_handler::{{closure}}::h72d68d3a77e0b718
   8:        0x10981bf18 - std::sys_common::backtrace::__rust_end_short_backtrace::h7c5e286792f94edb
   9:        0x1098206ba - _rust_begin_unwind
  10:        0x1098a6e4b - std::panicking::begin_panic_fmt::h6826a3ebe3a95a51
  11:        0x113069e39 - rustc_session::session::Session::incr_comp_session_dir::h9e4df312765624b0
  12:        0x111fd4c20 - rustc_incremental::persist::fs::garbage_collect_session_directories::hc278153e85e5a69e
  13:        0x10ecd51e5 - rustc_session::utils::<impl rustc_session::session::Session>::time::hfb85c7a36ca241c4
  14:        0x10ed15384 - rustc_interface::passes::register_plugins::hcbb989c71900c709
  15:        0x10ed48eb8 - rustc_interface::queries::Queries::register_plugins::hbe269a7365ea56fb
  16:        0x10eb4a093 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::heacbf49337f5fb9d
  17:        0x10eb27321 - rustc_span::with_source_map::h3927afb6bcf6a169
  18:        0x10eb457c9 - scoped_tls::ScopedKey<T>::set::h5608e7cc9397961b
  19:        0x10eb4d644 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9b82f31f81e95856
  20:        0x10eae05bc - core::ops::function::FnOnce::call_once{{vtable.shim}}::h5baa2aca5ae17340
  21:        0x10982eb7d - std::sys::unix::thread::Thread::new::thread_start::he3e6719579180a65
  22:     0x7fff5a5cd2eb - __pthread_body
  23:     0x7fff5a5d0249 - __pthread_start

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.48.0 (7eac88abb 2020-11-16) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: aborting due to previous error

error: could not compile `cynon`

Caused by:
  process didn't exit successfully: `rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=f8228d0fe8773068 -C extra-filename=-f8228d0fe8773068 --out-dir /Volumes/server/data/Matthias/prj/rust/cynon/target/debug/build/cynon-f8228d0fe8773068 -C incremental=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/incremental -L dependency=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/deps --extern prost_build=/Volumes/server/data/Matthias/prj/rust/cynon/target/debug/deps/libprost_build-0de83129d3e4f190.rlib` (exit code: 101)

The source for the panic is:

 871     pub fn incr_comp_session_dir(&self) -> cell::Ref<'_, PathBuf> {
 872         let incr_comp_session = self.incr_comp_session.borrow();
 873         cell::Ref::map(incr_comp_session, |incr_comp_session| match *incr_comp_session {
 874             IncrCompSession::NotInitialized => panic!(
 875                 "trying to get session directory from `IncrCompSession`: {:?}",
 876                 *incr_comp_session,
 877             ),
 878             IncrCompSession::Active { ref session_directory, .. }
 879             | IncrCompSession::Finalized { ref session_directory }
 880             | IncrCompSession::InvalidBecauseOfErrors { ref session_directory } => {
 881                 session_directory
 882             }
 883         })
 884     }

bors added a commit to rust-lang-ci/rust that referenced this issue May 29, 2021
…tebank

Don't panic when failing to initialize incremental directory.

This removes a panic when rustc fails to initialize the incremental directory. This can commonly happen on various filesystems that don't support locking (often various network filesystems). Panics can be confusing and scary, and there are already plenty of issues reporting this.

This has been panicking since 1.22 due to I think rust-lang#44502 which was a major rework of how things work. Previously, things were simpler and the [`load_dep_graph`](https://github.com/rust-lang/rust/blob/1.21.0/src/librustc_incremental/persist/load.rs#L43-L65) function would emit an error and then continue on without panicking. With 1.22, [`load_dep_graph`](https://github.com/rust-lang/rust/blob/1.22.0/src/librustc_incremental/persist/load.rs#L44) was changed so that it assumes it can load the data without errors. Today, the problem is that it calls [`prepare_session_directory`](https://github.com/rust-lang/rust/blob/fbf1b1a7193cda17008ab590e06ad28d9924023b/compiler/rustc_interface/src/passes.rs#L175-L179) and then immediately calls `garbage_collect_session_directories` which will panic since the session is `IncrCompSession::NotInitialized`.

The solution here is to have `prepare_session_directory` return an error that must be handled so that compilation stops if it fails.

Some other options:

* Ignore directory lock failures.
* Print a warning on directory lock failure, but otherwise continue with incremental enabled.
* Print a warning on directory lock failure, and disable incremental.
* Provide a different locking mechanism.

Cargo ignores lock errors if locking is not supported, so that would be a precedent for the first option. These options would require quite a bit more changes, but I'm happy to entertain any of them, as I think they all have valid justifications.

There is more discussion on the many issues where this is reported: rust-lang#49773, rust-lang#59224, rust-lang#66513, rust-lang#76251. I'm not sure if this can be considered closing any of those, though, since I think there is some value in discussing if there is a way to avoid the error altogether. But I think it would make sense to at least close all but one to consolidate them.
@ehuss
Copy link
Contributor

ehuss commented May 29, 2021

#85698 has changed it so that rustc does not panic in this situation, but it will still generate an error.

I'm going to close this as a duplicate of #49773 to consolidate the issues related to session locking.

@ehuss ehuss closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

5 participants