Skip to content

cargo panics when stdin to it is closed #6723

Closed
@soenkehahn

Description

@soenkehahn

Problem

When execing e.g. cargo build with a closed stdin file descriptor, it panics with:

thread '<unnamed>' panicked at 'failed to acquire jobserver token: early EOF on jobserver pipe', src/librustc_codegen_ssa/back/write.rs:1348:29

Expected behavior: cargo should treat this the same as if stdin was a valid file descriptor that nothing gets written to.

Steps

This can be reproduced e.g. by a rust program that:

  1. calls libc::close(libc::STDIN_FILENO),
  2. calls nix::unistd::execvp to run cargo build on a project.

Here's an example repo including a reproduce.sh script to show the bug: https://github.com/soenkehahn/entr-cargo-bug

Possible Solution(s)

I think cargo could check with fcntl(libc::STDIN_FILENO, libc::F_GETFD) whether stdin is still open.

Notes

This is motivated by trying to use cargo in conjunction with entr. Since this commit it closes the stdin of the called command when using the -r (restart) option.

Output of cargo version:

cargo 1.33.0 (f099fe94b 2019-02-12)

On linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-console-outputArea: Terminal output, colors, progress bar, etc.A-jobserverArea: jobserver, concurrency, parallelismC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions