Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force usage of a worker thread for stdin on all platforms #7058

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

alexcrichton
Copy link
Member

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.

This commit is a follow-up to bytecodealliance#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.
@alexcrichton alexcrichton requested a review from a team as a code owner September 18, 2023 20:11
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team September 18, 2023 20:11
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Sep 18, 2023
@pchickey
Copy link
Contributor

Weird behavior by MacOS but nothing we can do about it. Worker thread solution ought to be good enough. Thanks for tracking this one down, its a weird one.

@pchickey pchickey added this pull request to the merge queue Sep 19, 2023
Merged via the queue into bytecodealliance:main with commit 5359a8c Sep 19, 2023
18 checks passed
eduardomourar pushed a commit to eduardomourar/wasmtime that referenced this pull request Sep 22, 2023
…liance#7058)

This commit is a follow-up to bytecodealliance#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.
@alexcrichton alexcrichton deleted the stdin-always-worker branch October 25, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants