-
Notifications
You must be signed in to change notification settings - Fork 128
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
Don't panic on broken pipes when built without termcolor #221
Comments
My original issue had wrong assumption. The process doesn't hang, but keeps going in case when using use std::io::Write;
fn main() {
env_logger::builder()
.target(env_logger::Target::Stdout)
.init();
for i in 0.. {
log::info!("{}", i);
std::thread::sleep(std::time::Duration::from_secs(1));
std::io::stderr().write(b"hello\n").unwrap();
}
} this continues to print hello after stdout is closed so the process continues to run but log output is just lost: % cargo build --features termcolor && RUST_LOG=info /tmp/rust/target/debug/envltest | head -n3
Compiling envltest v0.1.0 (/Users/oherrala/tmp/envltest)
Finished dev [unoptimized + debuginfo] target(s) in 1.15s
[INFO envltest] 0
hello
[INFO envltest] 1
hello
[INFO envltest] 2
hello
hello
hello
hello
^C |
Could you clarify what you feel the expected behavior would be? Generally, logging is a never-fail operation, so I can't really see that |
@epage I expect the behavior to be the same in the two scenarios (with and without termcolor crate). So either panic or continue going. This difference of behavior was IIRC quite challenging to debug when we encountered this issue. |
Ah, I had missed that you were contrasting behavior without that feature. I would describe the panic as a bug and renamed the issue accordingly. |
Hmm, this was broken in #82 with the explanation // This impl uses the `eprint` and `print` macros
// instead of using the streams directly.
// This is so their output can be captured by `cargo test` I wonder what those macros do differently with tests. |
Also, note when fixing this, we also use |
Depending on if
termcolor
crate is used or notenv_logger
's behavior on closed stderr (or stdout) is different. When usingtermcolor
and the output is closed the process just hangs. When not usingtermcolor
a panic occurs because of broken pipe and process is terminated.I'm not sure how this case should work. Hanging indefinitely is bad and might lead to hard to debug issues. But to panic without possibility to recover is also bad.
An example for reproducing and testing (tested on macOS 11.6):
Cargo.toml:
main.rs:
When env_logger is build with no default features (as seen in Cargo.toml) the process is terminated as soon as stdout is closed (
head -n3
takes three lines and closes stdout):however, when compiled with
termcolor
crate the process just hangs until the process is terminated manually:Backtrace of broken pipe:
The text was updated successfully, but these errors were encountered: