Skip to content

cargo test --doc from make -j always triggers "failed to connect to jobserver from environment" #14407

Closed
@Deewiant

Description

@Deewiant

Problem

Having a Makefile run cargo test --doc, even with the command flagged as recursive with + so that make -j enables the jobserver for it, always triggers the rustc warning about a jobserver issue ("failed to connect to jobserver from environment variable"). I expect this to not happen.

I'm not sure what the "actual" impact beyond the warning is, since at least compiling dependency crates seems to follow the -j as expected. Maybe it only affects the compilation step for the final doctest binaries?

I guessed that this is most likely a cargo issue, although the interaction among cargo/rustdoc/rustc for doctests isn't very clear to me so maybe the root cause lies somewhere else.

Steps

  1. cargo new --lib foo && cd foo && printf 'doctests:\n\t+cargo test --doc' | make -j2 -f -

Results on my system (GNU Make 4.3, cargo 1.80.1):

    Creating library `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
cargo test --doc
   Compiling foo v0.1.0 (/tmp/foo)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.19s
   Doc-tests foo
warning: failed to connect to jobserver from environment variable `MAKEFLAGS=" -j2 --jobserver-auth=3,4"`: cannot open file descriptor 3 from the jobserver environment variable value: Bad file descriptor (os error 9)
  |
  = note: the build environment is likely misconfigured


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Changing --doc to --lib does not trigger the issue:

    Creating library `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
cargo test --lib
   Compiling foo v0.1.0 (/tmp/foo)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.45s
     Running unittests src/lib.rs (target/debug/deps/foo-8236ccd36d2d63e2)

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

And removing --doc triggers it only during the doctests stage:

    Creating library `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
cargo test
   Compiling foo v0.1.0 (/tmp/foo)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.43s
     Running unittests src/lib.rs (target/debug/deps/foo-8236ccd36d2d63e2)

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests foo
warning: failed to connect to jobserver from environment variable `MAKEFLAGS=" -j2 --jobserver-auth=3,4"`: cannot open file descriptor 3 from the jobserver environment variable value: Bad file descriptor (os error 9)
  |
  = note: the build environment is likely misconfigured


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Possible Solution(s)

No response

Notes

The only workaround I've come up with is to use MAKEFLAGS= cargo test --doc, but that of course causes the cargo test --doc invocation to use more parallelism than given to make -j, potentially oversubscribing the CPU. cargo test --doc -j1 can then be used as an additional workaround, with the natural downside of slowing down compilation a lot.

Version

cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: rustdoc --testA-jobserverArea: jobserver, concurrency, parallelismC-bugCategory: bugS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions