Skip to content

Restore TCP read backpressure after a cancelled receive - #1424

Merged
agronholm merged 3 commits into
agronholm:masterfrom
Master-Norna:fix/receive-cancellation-backpressure
Oct 18, 2026
Merged

agronholm merged 3 commits into
agronholm:masterfrom
Master-Norna:fix/receive-cancellation-backpressure

Conversation

@Master-Norna

@Master-Norna Master-Norna commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

NOTE Erasing or replacing the contents of this template will result in your pull
request being summarily closed without consideration!

Changes

Fixes #1423.

Pause transport reads in a finally block when leaving the receive wait.
Cancellation previously skipped this step, allowing incoming TCP data (including
TLS ciphertext) to accumulate without an active receiver. The fix preserves
cancellation and buffered data without closing the connection.

The regression test cancels receive() and checks that the transport has
paused reading, using the simpler test suggested in review.

Local validation of the simplified test (Windows, CPython 3.12):

  • All 3 IPv4 asyncio configurations fail without the fix and pass with it.
  • Related TCP/stream tests: 558 passed, 142 deselected after excluding IPv6
    and the two known environment-failing test groups.
  • The 8 IPv6-related connection failures and 75 native-Windows mypy diagnostics
    are unchanged from the pre-simplification PR baseline. Other pre-commit hooks pass.
  • Linux/macOS runtime tests, Python 3.10, uvloop, and the full repository suite
    were not rerun for this simplified test.

No documentation update is needed: this restores the intended backpressure behavior.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (in docs/), in case of behavior changes or new
    features
  • You've added a changelog fragment (in changelog.d/).

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.

Updating the changelog

Add a news fragment file in the changelog.d/ directory, named
<issue or PR number>.<type>.rst, where <type> is one of:

  • breaking: backwards incompatible changes
  • added: new features
  • changed: other user-visible changes
  • fixed: bug fixes

If, say, your patch fixes issue #123, create changelog.d/123.fixed.rst
containing only a brief summary of the change, like this:

Fixed big bad boo-boo in task groups

The issue link and the credit for your pull request are added automatically on release.
If there's no issue linked, name the file after your pull request instead by adding the
fragment after you've created the PR.

Comment thread tests/test_sockets.py

@agronholm agronholm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks.

@agronholm
agronholm merged commit 6219807 into agronholm:master Oct 18, 2026
20 checks passed
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.

Cancelling TCP receive leaves transport reads enabled on asyncio

2 participants