Skip to content

Preserve file descriptor blocking mode in add_reader and add_writer - #761

Open
HyunsikParker wants to merge 1 commit into
MagicStack:masterfrom
HyunsikParker:fix-712-preserve-fd-blocking
Open

Preserve file descriptor blocking mode in add_reader and add_writer#761
HyunsikParker wants to merge 1 commit into
MagicStack:masterfrom
HyunsikParker:fix-712-preserve-fd-blocking

Conversation

@HyunsikParker

Copy link
Copy Markdown

Fixes #712.

libuv's uv_poll_init() switches the supplied file descriptor to nonblocking mode. uvloop left that change in place after add_reader() or add_writer(), while the asyncio selector loop preserves the original mode.

This records the mode before initializing the poll handle and restores it once initialization finishes. If restoring it fails, the initialized handle is closed before the error is raised.

The regression test covers reader and writer registration and checks the descriptor both while registered and after removal. The same test runs against uvloop and the asyncio reference loop.

Tests:

  • .venv/bin/python -m unittest -v tests.test_sockets (35 passed, 1 skipped)
  • With test_fs_event_rename excluded, 528 tests passed with PYTHONASYNCIODEBUG=1 and again with PYTHONASYNCIODEBUG=0 (39 skipped in each run)
  • The full suite also exposed the existing intermittent macOS test_fs_event_rename failure. Isolated reruns produced one pass and one CHANGE versus RENAME failure.

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.

inconsistent file descriptor blocking state when running in asyncio vs uvloop

1 participant