You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hangs if procedural macro prints output when stdout is closed #8245
use proc_macro::TokenStream;#[proc_macro]pubfnrepro(_input:TokenStream) -> TokenStream{// On my machine <202 lines terminates successfully.// >=202 lines hangs.for i in0..1000{println!("{}", i);}TokenStream::new()}
src/main.rs
repro::repro!();fnmain(){}
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
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.
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.
Activity
ehuss commentedon 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.
Auto merge of #8247 - ehuss:output-hang, r=alexcrichton