Skip to content

Fix HTTP/2 response stalls behind concurrent network reads - #1334

Open
AdityaSreevatsaK wants to merge 2 commits into
pydantic:mainfrom
AdityaSreevatsaK:fix/http2-read-starvation-1300-ready
Open

AdityaSreevatsaK wants to merge 2 commits into
pydantic:mainfrom
AdityaSreevatsaK:fix/http2-read-starvation-1300-ready

Conversation

@AdityaSreevatsaK

@AdityaSreevatsaK AdityaSreevatsaK commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1300.

Under concurrent HTTP/2 requests, a response can remain undelivered even after its events have been received and queued. Another stream may acquire the shared read lock and block on a subsequent network read, delaying an already-completed response.

Changes

  • Introduce per-connection read-completion notifications, allowing waiting streams to process queued events without acquiring the read lock.
  • Preserve single-reader coordination and recheck queued responses and flow-control availability before additional reads.
  • Update both synchronous and asynchronous implementations.
  • Add deterministic regression tests covering asyncio, Trio and readiness races.

Testing

Full test suite passed: Python 3.11–3.15.

  • Ruff, mypy, packaging and documentation checks passed.
  • 100% test coverage achieved.
  • Generated synchronous/asynchronous code consistency verified.
  • Security analysis passed.
  • CodSpeed benchmarks executed, but results could not be uploaded because of fork-specific 401 authorisation.

CI: https://github.com/AdityaSreevatsaK/httpx2/actions/runs/43293561851

Security: https://github.com/AdityaSreevatsaK/httpx2/actions/runs/43293561652

Related work

PR #1298 refactors HTTP/2 stream ownership and modifies overlapping code. This change focuses specifically on coordinating network reads and waking streams with queued events.

The implementation has been prepared separately to allow review and integration with the ongoing HTTP/2 work.

Checklist

Documentation was not changed because the fix corrects internal scheduling behaviour.

Prepared with AI assistance. The changes and test results have been reviewed.

View guided diff

@veria-ai

veria-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing AdityaSreevatsaK:fix/http2-read-starvation-1300-ready (d5e90b5) with main (f4f65c1)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/httpcore2/test_http2_read_dispatch.py">

<violation number="1" location="tests/httpcore2/test_http2_read_dispatch.py:53">
P3: This comment describes the old read-lock queueing, but waiting streams now block on the `_read_event` completion event, not `_read_lock`. Update it to match the mechanism the test relies on.</violation>
</file>

This branch has not been deployed

No deployments
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.

HTTP/2: a received response waits until more data arrives on the connection

1 participant