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

poll.poll may return non readable events despite the only registered interest being for readables #1855

Open
glandium opened this issue Jan 13, 2025 · 5 comments

Comments

@glandium
Copy link

Here is a reproducer:

use mio::windows::NamedPipe;
use mio::{Events, Interest, Poll, Token};
use std::env;
use std::os::windows::io::{FromRawHandle, IntoRawHandle};
use std::process::{Command, Stdio};

fn main() {
    if env::var("FOO").is_ok() {
        println!("Hello, world!");
    } else {
        let mut proc = Command::new(std::env::current_exe().unwrap())
            .env("FOO", "1")
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();

        let mut out =
            unsafe { NamedPipe::from_raw_handle(proc.stdout.take().unwrap().into_raw_handle()) };

        let mut events = Events::with_capacity(16);
        let mut poll = Poll::new().unwrap();
        poll.registry()
            .register(&mut out, Token(0), Interest::READABLE)
            .unwrap();
        poll.poll(&mut events, None).unwrap();
        dbg!(events);
        proc.wait().unwrap();
    }
}

The dbg prints:

[src/main.rs:24:9] events = [
    Event {
        token: Token(
            0,
        ),
        readable: false,
        writable: true,
        error: false,
        read_closed: false,
        write_closed: fakse,
        priority: false
        aio: false,
        lio: false,
        details: event {
            flags: POLL_SEND,
            data: 0,
        },
    },
]
@Thomasdezeeuw
Copy link
Collaborator

Stdout isn't usually opened for reading, can you reproduce this on a handle/socket that can actually be used for reading?

Also the dbg! output contains fakse?

@glandium
Copy link
Author

Stdout isn't usually opened for reading, can you reproduce this on a handle/socket that can actually be used for reading?

It's the stdout of the subprocess. So it is to be used for reading.
I've also now discovered that I'm also getting readable events when there's nothing more to read (read returns Ok(0)).

Also the dbg! output contains fakse?

I didn't copy/paste, so it's just a typo.

@Darksonn
Copy link
Contributor

Darksonn commented Jan 15, 2025

Isn't this just "spurious events are possible"?

I've also now discovered that I'm also getting readable events when there's nothing more to read (read returns Ok(0)).

Readable interest is used to signal that EOF has arrived, so that's normal.

@glandium
Copy link
Author

I've also now discovered that I'm also getting readable events when there's nothing more to read (read returns Ok(0)).

Readable interest is used to signal that EOF has arrived, so that's normal.

Indefinitely? (repolling after getting Ok(0) still returns a readable event ; that only happens on Windows)

@Thomasdezeeuw
Copy link
Collaborator

I'm not sure, it could very well be a bug in Mio's NamedPipe code, but at the moment we don't really have a Windows expert to figure it out, we have some more issues in this area (https://github.com/tokio-rs/mio/issues?q=is%3Aissue+is%3Aopen+named+pipe), but no one to fix them :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants