Skip to content

Fix HTTP/2 stalls when early responses leave unread request bodies - #395

Open
AdityaSreevatsaK wants to merge 1 commit into
pgjones:mainfrom
AdityaSreevatsaK:fix/http2-early-response-deadlock-393-submission
Open

AdityaSreevatsaK wants to merge 1 commit into
pgjones:mainfrom
AdityaSreevatsaK:fix/http2-early-response-deadlock-393-submission

Conversation

@AdityaSreevatsaK

@AdityaSreevatsaK AdityaSreevatsaK commented Nov 15, 2026 •

Copy link
Copy Markdown

Summary

Fixes #393.

When an ASGI application sends an early HTTP/2 response without consuming the request body, the bounded application input queue can become full.

Subsequent incoming DATA frames can then block the protocol reader, preventing other streams on the same connection from progressing and potentially delaying graceful shutdown.

This change ensures that completed or disconnected streams cannot indefinitely block the connection.

Changes

  • Introduce a bounded, finishable ASGI input queue shared by asyncio and Trio workers.
  • Release blocked producers and receivers when the application finishes.
  • Distinguish between response completion and transport disconnection:
    • Response completion: Discard unread request data and release blocked tasks.
    • Transport disconnection: Preserve queued request messages so applications can finish processing them.
  • Preserve existing queue capacity and backpressure behaviour, including Trio's zero-capacity rendezvous semantics.
  • Ignore late request-body events after the response has completed.

Regression Tests

Added coverage for:

  • Early responses with 0, 1, 40 and 60 KiB of request data.
  • Multiple HTTP/2 requests sharing a connection, including 20 subsequent streams.
  • Normal request-body consumption and client resets.
  • Graceful shutdown with an HTTP/2 client still connected.
  • Asyncio and Trio queue backpressure, completion and disconnection.
  • HTTP/1.1 compatibility, including half-closed connections.

Validation

Tested in the forked CI run - https://github.com/AdityaSreevatsaK/hypercorn/actions/runs/43695100109.

Results:

  • Python 3.10–3.14: 220 passed, 2 failed per version.
  • Black / isort: Passed.
  • Flake8: Passed.
  • Package build: Passed.
  • HTTP/2 compliance (asyncio and Trio): Passed.
  • Autobahn (asyncio and Trio): Passed.

Known unrelated CI failures:

The implementation-specific regression tests pass across all five tested Python versions.

Scope

This change intentionally does not modify protocol/h2.py.

Handling DATA frames received after a stream has already been removed is a separate concern addressed by #391.

Thanks to @tahsinrk for the detailed reproduction in #393.

…gjones#393)

Release blocked ASGI input producers on response completion while
preserving unread queued input during transport disconnect.

Add asyncio and Trio queue regressions, HTTP/2 multiplexing coverage,
and HTTP/1.1 half-close compatibility tests.

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.

Unread request data after an early response can deadlock HTTP/2 streams and shutdown

1 participant