Skip to content

incremental compilation: could not create session directory lock file: No locks available (os error 37) #49773

Open

Description

@szignal

I was unable to incrementally compile using cargo build.

I had added the rand dependency to the toml file, per the advice of the Guessing Game exercise in Rust Programming Language (Second Edition).

Before this particular error, I had just finished setting up a synced folder with NFS on my vagrant box (ubuntu 16.04) where rust was installed. There is some issue using the default vagrant shared folder setup with rust.

I tried this code:

use std::io;

fn main() {
    println!("Guess the number");

    println!("Please input your guess.");

    let mut guess = String::new();

    io::stdin().read_line(&mut guess)
        .expect("Failed to read line");

    print!("You guessed: {}", guess);
}

I expected to see this happen:

compile

Instead, this happened:

    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading rand v0.3.22                                                       
 Downloading libc v0.2.40                                                       
 Downloading rand v0.4.2                                                        
   Compiling libc v0.2.40                                                       
   Compiling rand v0.4.2
   Compiling rand v0.3.22
   Compiling guessing_game v0.1.0 (file:///Rust/projects/guessing_game)
error: incremental compilation: could not create session directory lock file: No locks available (os error 37)

thread 'rustc' panicked at 'librustc/session/mod.rs:727: Trying to get session directory from IncrCompSession `NotInitialized`', librustc/session/mod.rs:1180:26
note: Run with `RUST_BACKTRACE=1` for a backtrace.

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.25.0 (84203cac6 2018-03-25) running on x86_64-unknown-linux-gnu

error: Could not compile `guessing_game`.

rustc --version --verbose:

rustc 1.25.0 (84203cac6 2018-03-25)
binary: rustc
commit-hash: 84203cac67e65ca8640b8392348411098c856985
commit-date: 2018-03-25
host: x86_64-unknown-linux-gnu
release: 1.25.0
LLVM version: 6.0

Backtrace:

thread 'rustc' panicked at 'librustc/session/mod.rs:727: Trying to get session directory from IncrCompSession `NotInitialized`', librustc/session/mod.rs:1180:26
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
   6: rustc::session::opt_span_bug_fmt::{{closure}}
   7: rustc::ty::context::tls::with_opt
   8: rustc::session::opt_span_bug_fmt
   9: rustc::session::bug_fmt
  10: rustc::session::Session::incr_comp_session_dir
  11: rustc_incremental::persist::fs::garbage_collect_session_directories
  12: rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}}
  13: rustc_driver::driver::phase_2_configure_and_expand_inner
  14: rustc_driver::driver::compile_input
  15: rustc_driver::run_compiler

Activity

  1. glaubitz commented on Apr 9, 2018

    @glaubitz
    Contributor

    This is an issue we are currently seeing on linux-sparc64 as well [1]:

    error: incremental compilation: could not create session directory lock file: No such process (os error 3)
    
    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.24.1 running on sparc64-unknown-linux-gnu
    
    thread 'rustc' panicked at 'src/librustc/session/mod.rs:665: Trying to get session directory from IncrCompSession `NotInitialized`', src/librustc/session/mod.rs:1141:26
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    
    error: Could not compile `build_helper`.
    warning: build failed, waiting for other jobs to finish...
    

    I have not yet figured out where this comes from. The same rust version worked fine in the past.

    [1] https://buildd.debian.org/status/fetch.php?pkg=rustc&arch=sparc64&ver=1.25.0%2Bdfsg1-1%7Eexp2&stamp=1523052949&raw=0

    CC @jrtc27 @psumbera @mkarcher

  2. michaelwoerister commented on May 3, 2018

    @michaelwoerister
    Member

    NFS does not support locking files very well, I guess. It would be good if there was some way to make Cargo put the incremental folder somewhere else (into /tmp for example).

    cc @rust-lang/cargo

  3. added
    A-incr-compArea: Incremental compilation
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on May 3, 2018
  4. jrtc27 commented on May 3, 2018

    @jrtc27

    Although the original report mentions NFS, we're not using NFS for the sparc64 buildds; the two issues have similar but different error messages ("No locks available" vs "No such process") so they could well be different problems.

  5. michaelwoerister commented on May 3, 2018

    @michaelwoerister
    Member

    @jrtc27, yes, sounds like a different root cause.

  6. alexcrichton commented on May 3, 2018

    @alexcrichton
    Member

    In Cargo we disable file locking whenever NFS is detected, although that may not work well for rustc as it's semi-reasonable to expect Cargo to not be run in parallel much on one system but rustc probably is being executed in parallel by Cargo at least.

    An alternative to moving the incremental directory is moving the locks for the incremental directory. I've considered this for Cargo where we actually want to enable file locking on NFS directories. That'd require more intrusive support in rustc, though.

  7. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jul 7, 2018
  8. glaubitz commented on Sep 22, 2018

    @glaubitz
    Contributor

    If anyone wants to reproduce this problem, there are sparc64 porterboxes available in the gcc compile farm, both running Solaris and Linux. Any open source developer can apply for an account:

    https://cfarm.tetaneutral.net/machines/list/

  9. michaelwoerister commented on Sep 24, 2018

    @michaelwoerister
    Member

    Is this on a file system that should support locks in general?

    An alternative to moving the incremental directory is moving the locks for the incremental directory. I've considered this for Cargo where we actually want to enable file locking on NFS directories. That'd require more intrusive support in rustc, though.

    As long as we don't want to support two different machines working on the same NFS share simultaneously (which we don't really do anyway), we could indeed just allocate that lock files in /tmp. The only real restriction for lock files is that they mustn't be contained in the session directory that they protect.

  10. glaubitz commented on Sep 24, 2018

    @glaubitz
    Contributor

    Is this on a file system that should support locks in general?

    It's a standard off-the-shelf installation of Debian on ext4. Nothing special. There is no NFS or anything involved and it affects sparc64 machines with the same configuration as comparable x86_64 machines.

  11. michaelwoerister commented on Sep 24, 2018

    @michaelwoerister
    Member

    Interesting. That's unexpected.

  12. glaubitz commented on Sep 24, 2018

    @glaubitz
    Contributor

    You can test it yourself on the Linux/sparc64 porterbox available in the gcc compile farm. It's a rather fast machine.

  13. michaelwoerister commented on Sep 24, 2018

    @michaelwoerister
    Member

    I've requested an account. Thanks for the tip!

  14. 2 remaining items

  15. michaelwoerister commented on Oct 23, 2018

    @michaelwoerister
    Member

    @glaubitz Yes, I have an account. I haven't gotten around to actually using it though.

  16. glaubitz commented on Dec 20, 2018

    @glaubitz
    Contributor

    @michaelwoerister @alexcrichton

    @karcherm has had a look at the Rust sources and he found the problem rather quickly. Rust is hard-wiring the constants for the fnctls from glibc assuming they are constant across which they are not.

    Compare:

    https://github.molgen.mpg.de/git-mirror/glibc/blob/master/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h#L53

    and:

    https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_data_structures/flock.rs.html#45

    Rust is trying to call "Set Lock" and uses function control number 6. But that's "F_SETOWN" on sparc64 which expects a PID as a parameter which is why the error message is "No such process".

  17. michaelwoerister commented on Dec 20, 2018

    @michaelwoerister
    Member

    Awesome find, @karcherm & @glaubitz!

  18. jonathan-sha commented on Mar 23, 2020

    @jonathan-sha

    I get this when compiling files stored on WSL2, but running cargo on windows. So running on windows and compiling on this path:

    \\wsl$\Ubuntu\home\...
    
  19. nfwatsoncom commented on May 10, 2020

    @nfwatsoncom

    Ditto from @tpn-station ... I likewise have source on WSL2 (Ubuntu-20.04 w/ native Kernel) filesystem with Ubuntu's root FS mounted as drive "N:" in Windows. To Windows it looks like a network drive. My Rust project is configured for Windows build (as opposed to running CLion in Ubuntu).

    I also tried avoiding the "N:" drive-letter mapping and specifying source files directly as "'\\wsl$\Ubuntu-20.04\home..." and hit the same error.

  20. DrDinosaur commented on May 26, 2020

    @DrDinosaur

    Same issue on WSL 2 as above.

  21. daswafford commented on Jun 6, 2020

    @daswafford

    Hi, I think I am seeing a related error. I was trying to build the hello world example from https://rust-cli.github.io/book/tutorial/setup.html and when issuing cargo run, get:

    dswafford@Davids-Mac-mini.local:/Volumes/dswafford/CODE/rust/hello/grrs$cargo run --verbose
       Compiling grrs v0.1.0 (/Volumes/dswafford/CODE/rust/hello/grrs)
         Running `rustc --crate-name grrs --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=a4d4421a81652fc4 -C extra-filename=-a4d4421a81652fc4 --out-dir /Volumes/dswafford/CODE/rust/hello/grrs/target/debug/deps -C incremental=/Volumes/dswafford/CODE/rust/hello/grrs/target/debug/incremental -L dependency=/Volumes/dswafford/CODE/rust/hello/grrs/target/debug/deps`
    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', src/librustc_session/session.rs:690:48
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    
    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.44.0 (49cae5576 2020-06-01) running on x86_64-apple-darwin
    
    note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
    
    note: some of the compiler flags provided by cargo are hidden
    
    error: aborting due to previous error
    
    error: could not compile `grrs`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name grrs --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=a4d4421a81652fc4 -C extra-filename=-a4d4421a81652fc4 --out-dir /Volumes/dswafford/CODE/rust/hello/grrs/target/debug/deps -C incremental=/Volumes/dswafford/CODE/rust/hello/grrs/target/debug/incremental -L dependency=/Volumes/dswafford/CODE/rust/hello/grrs/target/debug/deps` (exit code: 101)
    

    I am on a MacOS computer running 10.15.4 and the current working directory where I ran "cargo" run" is an smb mount to a network-based file server (Ubuntu):

    dswafford@Davids-Mac-mini.local:/Volumes/dswafford/CODE/rust/hello/grrs$mount
    ...
    //dswafford@nas.ntwk.cc/dswafford on /Volumes/dswafford (smbfs, nodev, nosuid, mounted by dswafford)
    
  22. Tarnadas commented on Nov 10, 2020

    @Tarnadas

    Current workaround for Windows compiling a project in WSL2:

    # powershell
    $env:CARGO_INCREMENTAL=0; cargo build

    see #66513 (comment)

  23. ms140569 commented on Dec 29, 2020

    @ms140569

    I'm facing the very same issue (Rust 1.48.0, Mac -> SMB), documented here:

    #76251 (comment)

    Both of these two workarounds are valid on Mac OSX:

    CARGO_INCREMENTAL=0 cargo build
    CARGO_TARGET_DIR=/tmp cargo build
    

    Sorry, if i commented/documented on the wrong issue ...

  24. ehuss commented on May 29, 2021

    @ehuss
    Contributor

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

    Leaving this open as I think it is still worthwhile to consider what other options there are for locking, or if certain situations can be fixed.

    A summary of the things people have reported:

  25. kngrektor commented on Sep 17, 2021

    @kngrektor

    regarding SMB mounts on macOS: I checked ages ago and flock seems to work fine with SMB mounts it's specifically F_SETLK with fcntl that doesn't work. I believe this means that the Linux code path would work fine for macOS but either way a fallback would be nice.

  26. tommythorn commented on Jan 21, 2022

    @tommythorn

    How is rustc deciding that locks aren't working? Is it just a heuristic? Because my NFS4 mount on macOS does support locks and they work. If it's a heuristic can it be overruled?

  27. Xymist commented on Apr 20, 2022

    @Xymist

    This may or may not be useful, but for possible future Googlers....

    I keep my dev folder on a TrueNAS server and access via an NFS share. Ended up with this issue after moving from Core to Scale. The fix was to turn on both "Enable NFSv4" and "NFSv3 ownership model for NFSv4" in the NFS service settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions