Skip to content

Commit

Permalink
Force usage of a worker thread for stdin on all platforms (#7058)
Browse files Browse the repository at this point in the history
This commit is a follow-up to #6833 to remove the `unix` module for
handling stdio which sets stdin to nonblocking mode. I've just now
discovered that on macOS at least configuring `O_NONBLOCK` for stdin
affects the stdout/stderr descriptors too. This program for example will
panic:

    fn main() {
        unsafe {
            let r = libc::fcntl(
                libc::STDIN_FILENO,
                libc::F_SETFL,
                libc::fcntl(libc::STDIN_FILENO, libc::F_GETFL) | libc::O_NONBLOCK,
            );
            assert_eq!(r, 0);
        }

        loop {
            println!("hello");
        }
    }

It was originally assumed that updating the flags for stdin wouldn't
affect anything else except Wasmtime, but because this looks to not be
the case this commit removes the logic of registering stdin raw with
Tokio and instead unconditionally using the worker thread solution which
should work in all situations.
  • Loading branch information
alexcrichton authored Sep 19, 2023
1 parent 4cc3525 commit 5359a8c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 167 deletions.
7 changes: 0 additions & 7 deletions crates/wasi/src/preview2/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ use crate::preview2::{HostOutputStream, OutputStreamError, WasiView};
use bytes::Bytes;
use is_terminal::IsTerminal;

#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use self::unix::{stdin, Stdin};

#[allow(dead_code)]
mod worker_thread_stdin;
#[cfg(windows)]
pub use self::worker_thread_stdin::{stdin, Stdin};

// blocking-write-and-flush must accept 4k. It doesn't seem likely that we need to
Expand Down
160 changes: 0 additions & 160 deletions crates/wasi/src/preview2/stdio/unix.rs

This file was deleted.

0 comments on commit 5359a8c

Please sign in to comment.