Skip to content

Fix repeated SourceFd readiness with the poll selector - #2020

Closed
akasakariko wants to merge 1 commit into
tokio-rs:masterfrom
akasakariko:fix/sourcefd-poll-readiness
Closed

akasakariko wants to merge 1 commit into
tokio-rs:masterfrom
akasakariko:fix/sourcefd-poll-readiness

Conversation

@akasakariko

Copy link
Copy Markdown

Fixes #2018

Problem and Mechanism

poll(2) currently clears registered interests after readiness and relies on IoSourceState::do_io to rearm them on WouldBlock
Raw unix::SourceFd registrations do not pass through that wrapper so later events are lost

This fix adds an internal per-registration rearm_on_io flag in the poll selector
Mio-owned I/O retains its existing rearm behavior on WouldBlock
Registrations via unix::SourceFd keep their interests enabled with level-triggered readiness
SourceFd documentation is updated to explain this behavior
No public API change

Regression Coverage

Two regression tests in tests/unix_sourcefd.rs use std UnixStream descriptors registered through SourceFd:

  • Repeated readable readiness after WouldBlock
  • Repeated writable readiness after WouldBlock, changing token and interests via reregister, and deregistration

Tests exclude Miri and Emscripten due to existing Unix socketpair limitations

Validation

  • Before fix both new regressions fail with forced poll and pass with native epoll/kqueue, after fix both pass
  • Linux aarch64 via Colima with Rust 1.96.1: cargo test --all-features and cargo test --release --all-features both PASS, with native epoll and with RUSTFLAGS='--cfg mio_unsupported_force_poll_poll'
  • macOS aarch64 Rust 1.98: cargo test --all-features PASS on native kqueue, targeted forced-poll regressions PASS
  • macOS native cargo clippy --all-targets --all-features -- -D warnings PASS
  • rustfmt --check on every Rust file and git diff --check PASS
  • cargo hack check --feature-powerset and cargo hack check --tests --feature-powerset --features log PASS with native and forced-poll backends on macOS
  • cargo +1.71.1 check --all-features PASS with native and forced-poll backends

Limitations

  • macOS forced-poll full suite still has pre-existing failures, each failing test also failed on an unmodified baseline run
  • Linux Clippy and macOS forced-poll Clippy fail on existing diagnostics reproduced on baseline
  • Test feature-powerset without log fails on existing tests importing log on baseline too, library powerset passes and test powerset with log enabled passes
  • Haiku runtime not available and not tested
  • No GitHub CI has run yet

@akasakariko

Copy link
Copy Markdown
Author

@Thomasdezeeuw Could you share why this was closed? I'd like to know whether the approach is wrong or you'd prefer a different fix

@Thomasdezeeuw

Copy link
Copy Markdown
Collaborator

I'm not going to review an AI pr without prior discussion.

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.

poll(2) selector: SourceFd gets only the first event

2 participants