Skip to content

Commit

Permalink
Use a worker thread for stdin on Unix with preview2
Browse files Browse the repository at this point in the history
Currently stdin on Unix uses `AsyncFd` after setting the nonblocking flag
on the stdin file descriptor. This cannot generally be relied on to
succeed or work well in cases such as:

* On Linux if stdin is a file (e.g. `wasmtime < ./foo.txt`) then that
  can't be added to epoll and `epoll_ctl` fails with EPERM.

* On macOS if stdin is `/dev/null` that can't be added to kqueue and
  fails with `EINVAL`.

Currently this causes Wasmtime to panic due to a `.unwrap()` in failing
to register stdin. To fix this this commit removes the Unix-specific
logic using `AsyncFd` and instead falls back to unconditionally using a
spawned thread like Windows does. This does mean it's a little less
lightweight but should be more robust in situations like the above.
  • Loading branch information
alexcrichton committed Aug 10, 2023
1 parent e6cc402 commit 378be36
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 140 deletions.
7 changes: 0 additions & 7 deletions crates/wasi/src/preview2/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use crate::preview2::pipe::AsyncWriteStream;

#[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};

pub type Stdout = AsyncWriteStream;
Expand Down
133 changes: 0 additions & 133 deletions crates/wasi/src/preview2/stdio/unix.rs

This file was deleted.

0 comments on commit 378be36

Please sign in to comment.