Skip to content

println does not panic when stdout is broken #57931

@NickeZ

Description

@NickeZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions