Skip to content

Preserve input events after asynchronous read cancellation - #263

Open
omrzk wants to merge 1 commit into
gvalkov:mainfrom
omrzk:fix/cancelled-async-read
Open

omrzk wants to merge 1 commit into
gvalkov:mainfrom
omrzk:fix/cancelled-async-read

Conversation

@omrzk

@omrzk omrzk commented Nov 10, 2026

Copy link
Copy Markdown

Cancelling an asynchronous input read can leave a readiness callback that later reads the next event and tries to complete an already cancelled Future. This reports InvalidStateError; for async_read_one() and async_read_loop() it also consumes an event that a later read should receive.

Check that the destination Future is still pending before reading or advancing a batch. Retrieve batch exceptions even after cancellation, while preserving the original exception for active readers.

Fixes #123.

Validation: 12 native pipe/selector tests pass, covering all three async read APIs, cancellation followed by another read, successful reads and injected read errors. Six cancellation cases fail on main. The full suite has 23 passes and six failures requiring /dev/uinput; the same six hardware failures occur on clean main. Package build, wheel build and the CI Pylint error check pass on Python 3.14. No input hardware was exercised.

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.

Error after asyncio cancel

1 participant