Failed printing to stdout (when stdin is non blocking) | FFI

I am trying to debug this piece of code, where first I call fcntl to set the stdin as non blocking, then print in a loop. With the fcntl call, the print ultimately fails with the below error.

Rust Playground

thread 'main' panicked at 'failed printing to stdout: Resource temporarily unavailable (os error 11)', library/std/src/io/stdio.rs:1015:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
   2: std::io::stdio::print_to
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/stdio.rs:1015:9
   3: std::io::stdio::_print
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/stdio.rs:1027:5
   4: example1::main
             at ./examples/example1.rs:25:9
   5: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace

I am not sure what is going on. Here are some of the things I tried.

  1. Tried to reproduce the issue in C, but could not.
  2. Use 'Nightly'. Issue can be reproduced with Nightly toolchain.

Thanks

PS:

  1. Part of a larger project, where FFI is required.
  2. Rust playground is throwing a Json error. Probably it is down, and not related to my problem.
  3. For some reason the said error is only seen if I redirected the stderr to a file. Without the redirection, the program will fail and exit, but no error is printed.

Non-blocking stdio isn't supported. You'll have to do something like using writeln! and handling recoverable errors yourself if you need non-blocking.

1 Like

Thanks. But why do you think writing to stdio is causing problems when stdin is the one non blocking?

Oh, I missed that, sorry. Perhaps this phenomenon.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.