Skip to content

std::io doesn't work when stdout/stderr has O_NONBLOCK set #100673

Closed
@uarif1

Description

@uarif1

When stdout/stderr uses tty and has O_NONBLOCK set, the kernel driver returns -EAGAIN (https://elixir.bootlin.com/linux/v5.19/source/drivers/tty/tty_io.c#L952). This causes rust to panic, rather than try to print the same buffer again.

An example of when O_NONBLOCK is set on stdio is when using qemu serial.

I made an attempt to handle EAGAIN for std::io(#100594), but it was on generic code so not the right approach. Maybe there is a better approach to handle EAGAIN specifically for std::io and not panic?

To test this just change the stdout to O_NONBLOCK and then create 10 threads to print to stdout, C++ is able to print and finish to completion, but rust panics and crashes, so I think glibc also probably has similar support for O_NONBLOCK for stdout.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-unixOperating system: Unix-likeT-libsRelevant to the library 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