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

Hangs if procedural macro prints output when stdout is closed #8245

Closed
dtolnay opened this issue May 15, 2020 · 1 comment · Fixed by #8247
Closed

Hangs if procedural macro prints output when stdout is closed #8245

dtolnay opened this issue May 15, 2020 · 1 comment · Fixed by #8247
Assignees
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug P-high Priority: High regression-from-stable-to-beta Regression in beta that previously worked in stable.

Comments

@dtolnay
Copy link
Member

dtolnay commented May 15, 2020

Problem

Running cargo check | false (or more realistically cargo check | head) hangs if a macro prints more than a small number of lines to stdout.

Expected: same behavior as if the macro only prints a small number of lines to stdout, which is to not hang.

Steps

Cargo.toml

[package]
name = "repro"
version = "0.0.0"
edition = "2018"

[lib]
proc-macro = true

src/lib.rs

use proc_macro::TokenStream;

#[proc_macro]
pub fn repro(_input: TokenStream) -> TokenStream {
    // On my machine <202 lines terminates successfully.
    // >=202 lines hangs.
    for i in 0..1000 {
        println!("{}", i);
    }
    TokenStream::new()
}

src/main.rs

repro::repro!();

fn main() {}

Notes

  • Tested with current master branch of cargo (13bded9) and nightly rustc 1.45.0-nightly (a74d1862d 2020-05-14) on linux. /path/to/cargo/target/release/cargo check | head

  • Mentioning @ehuss because Ignore broken console output in some situations. #8236 looks relevant.

  • Nightly cargo panicks and hangs, so this is not a regression from Ignore broken console output in some situations. #8236 which does eliminate the panic.

  • I think the hang is cargo not rustc but I can't be sure. Reasoning: I ran cargo check --verbose to grab the last rustc invocation before the hang, and ran that rustc invocation piped to head, and that did not hang.

@dtolnay dtolnay added the C-bug Category: bug label May 15, 2020
@ehuss
Copy link
Contributor

ehuss commented May 15, 2020

Thanks for the high-quality report!

This is an unexpected consequence of #7838. Essentially there is a bounded message queue (to prevent buffering huge amounts of output in memory), but the loop that drains it is exiting when it shouldn't. Unfortunately I don't think there is a trivial fix. I'm thinking all the uses of ? need to be removed from the main loop. That's probably not too hard to do, but will need to investigate all the myriad of error cases. It should also probably handle if there is more than one error, and if that error is due to a closed stdout, only report that once.

I'll try to take a look at this soon.

@ehuss ehuss added A-console-output Area: Terminal output, colors, progress bar, etc. P-high Priority: High regression-from-stable-to-beta Regression in beta that previously worked in stable. labels May 15, 2020
@ehuss ehuss self-assigned this May 15, 2020
@bors bors closed this as completed in b781ec4 May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug P-high Priority: High regression-from-stable-to-beta Regression in beta that previously worked in stable.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants