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

println does not panic when stdout is broken #57931

Closed
NickeZ opened this issue Jan 27, 2019 · 2 comments
Closed

println does not panic when stdout is broken #57931

NickeZ opened this issue Jan 27, 2019 · 2 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@NickeZ
Copy link

NickeZ commented Jan 27, 2019

Using the regular hello world example but giving it either a closed stdout fd or a read-only stdout fd it doesn't panic. Is this expected behavior?

niklas @ niklas-ThinkPad-T480s : ~/projects/rust-test/println-panic (master #)
$ strace -e write cargo -q run --release 1>&-; echo "Exit status" $?
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(5, "|", 1)                        = 1
write(1, "Hello, World!\n", 14)         = -1 EBADF (Bad file descriptor)
+++ exited with 0 +++
Exit status 0
niklas @ niklas-ThinkPad-T480s : ~/projects/rust-test/println-panic (master #)
$ strace -e write cargo -q run --release 1</dev/null; echo "Exit status" $?
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(1, "Hello, World!\n", 14)         = -1 EBADF (Bad file descriptor)
+++ exited with 0 +++
Exit status 0
@NickeZ
Copy link
Author

NickeZ commented Jan 27, 2019

But on closed pipe it seems to error as it should. The code in the below example is simply the hello world in an infinite loop.

$ strace -e trace=write cargo -q run --release | grep -q Hello; echo "Exit status" $?
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(6, "|", 1)                        = 1
write(1, "Hello, World!\n", 14)         = 14
write(1, "Hello, World!\n", 14)         = 14
write(1, "Hello, World!\n", 14)         = 14
write(1, "Hello, World!\n", 14)         = 14
write(1, "Hello, World!\n", 14)         = 14
write(1, "Hello, World!\n", 14)         = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=28605, si_uid=1000} ---
write(1, "Hello, World!\n", 14)         = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=28605, si_uid=1000} ---
write(2, "thread '", 8thread ')                 = 8
write(2, "main", 4main)                     = 4
write(2, "' panicked at '", 15' panicked at ')         = 15
write(2, "failed printing to stdout: Broke"..., 52failed printing to stdout: Broken pipe (os error 32)) = 52
write(2, "', ", 3', )                      = 3
write(2, "libstd/io/stdio.rs", 18libstd/io/stdio.rs)      = 18
write(2, ":", 1:)                        = 1
write(2, "700", 3700)                      = 3
write(2, ":", 1:)                        = 1
write(2, "9", 19)                        = 1
write(2, "\n", 1
)                       = 1
write(2, "note: Run with `RUST_BACKTRACE=1"..., 51note: Run with `RUST_BACKTRACE=1` for a backtrace.
) = 51
write(1, "Hello, World!\n", 14)         = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=28605, si_uid=1000} ---
+++ exited with 101 +++
Exit status 0

@jonas-schievink jonas-schievink added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 27, 2019
@NickeZ
Copy link
Author

NickeZ commented Jan 27, 2019

It seems to be on purpose: rust-lang/rfcs#1014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants