Skip to content

Conversation

discord9
Copy link
Contributor

@discord9 discord9 commented Aug 21, 2025

CC #1755 tokio-rs/tokio#3789

as title, use a fix that on windows peek should reregister after either success or would block, so that it's behavior would be the same as on linux(see peek_readinesspeek_ok and peek_would_block).

This should fix windows peek problem, @Darksonn might want to take a look.

The problem it seems is that in src\sys\windows\selector.rs SockState::feed_event mio have to simulate Edge-triggered behavior and clean readable interest after send a readable interest, but since peek is also a kind of special read, it also cancelled interest to readable event, hence cause the blocking peek bug on windows because interest is lost so blocking is forever

edited: found out that under linux with cfg(mio_unsupported_force_poll_poll) peek would also have similiar problem so just write do_io on all platform instead

Alternatives

only do do_io on #[cfg(any(windows, mio_unsupported_force_poll_poll))] which also seem to pass all tests on all platform/cfg combination

@Darksonn
Copy link
Contributor

Reregister is an expensive operation and I don't think that's the solution we want.

@discord9
Copy link
Contributor Author

discord9 commented Aug 21, 2025

Reregister is an expensive operation and I don't think that's the solution we want.

How about handle peek event specially in feed_event on windows somehow(maybe add a is_peeking flag somewhere)? Maybe even a special Interest::Peek for it only on windows?

Also the CI test failed strangely, I don't understand why, the TestPoll failed with not found expected event)
but the Test (ubuntu-latest) successed, I don't understand why, also I don't think my patch affect behavior on linux platform so even more confused
Oh different rustcfg flag I see

@discord9 discord9 changed the title fix: windows peek reregister after success or would block fix: windows peek reregister after would block Aug 22, 2025
@discord9 discord9 changed the title fix: windows peek reregister after would block fix: peek reregister after would block Aug 25, 2025
@discord9
Copy link
Contributor Author

the falling CI seems related to #1883 and not caused by this patch

assert_eq!(stream2.write(&[0, 1, 2, 3]).unwrap(), 4);

// this panic with no event on windows if not re-register after would block peek
// becuase mio simulate edge-triggered behavior in `SockState::feed_event` and need reregister
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is outdated and can be removed.

@Thomasdezeeuw Thomasdezeeuw merged commit 8e5a4b5 into tokio-rs:master Aug 28, 2025
56 checks passed
@Thomasdezeeuw
Copy link
Collaborator

Thanks @discord9

@Sytten
Copy link

Sytten commented Sep 10, 2025

For what it is worth, this is the exact fix that I proposed 2 years ago.

@Thomasdezeeuw did something fundamentally changed in core for your opinion to change on that?

See #1756

@Darksonn
Copy link
Contributor

I think we just misunderstood the problem space last time we looked at it. I don't think there is anything more to it. Sorry about that.

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

Successfully merging this pull request may close these issues.

4 participants