Skip to content

Fix ASGI disconnect handling for HTTP/3 stream resets and connection termination - #383 - #384

Open
appunni-m wants to merge 3 commits into
pgjones:mainfrom
appunni-m:fix/h3-asgi-disconnect
Open

appunni-m wants to merge 3 commits into
pgjones:mainfrom
appunni-m:fix/h3-asgi-disconnect

Conversation

@appunni-m

Copy link
Copy Markdown

#383 :

Hypercorn’s HTTP/3 path did not propagate some QUIC disconnect events to the ASGI application.

When a client reset an HTTP/3 request stream, or when the underlying QUIC connection terminated, Hypercorn received the QUIC event but the corresponding ASGI application could remain unaware and continue waiting on receive().

The expected flow is:

QUIC StreamReset / ConnectionTerminated
        ↓
Hypercorn closes affected request stream(s)
        ↓
ASGI application receives
{"type": "http.disconnect"}

This change routes these HTTP/3 lifecycle events through Hypercorn’s existing StreamClosed handling.

For StreamReset, only the affected request stream is closed.

For ConnectionTerminated, all active request streams on that QUIC connection are closed.

This brings the HTTP/3 path in line with Hypercorn’s existing disconnect semantics and the ASGI HTTP disconnect event.

Reproduction

Before this change:

HTTP/3 request
    ↓
client resets stream
    ↓
Hypercorn receives StreamReset
    ↓
ASGI application keeps waiting on receive()

After this change:

HTTP/3 request
    ↓
client resets stream
    ↓
Hypercorn closes the request stream
    ↓
ASGI application receives http.disconnect

Relevant specifications:

  • ASGI HTTP spec — http.disconnect
  • RFC 9114 — HTTP/3 request cancellation
  • RFC 9000 — QUIC stream reset and connection termination

@appunni-m
appunni-m force-pushed the fix/h3-asgi-disconnect branch from 61536d5 to 05716d4 Compare October 4, 2026 12:17
@jlaine

jlaine commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Hi there, aioquic author here. Thanks for working on this! The ConnectionTerminated part looks good. The HTTP/3 layer has no event for it, so closing all the streams there is right.

For resets and STOP_SENDING, though, please don't intercept the QUIC events before H3Connection.handle_event(). The HTTP/3 layer needs to see them too. I tried this branch against aioquic 1.9.0 with a real client and found two problems:

  • If the client sends STOP_SENDING on a request and then keeps sending the request body, H3Protocol.handle() raises KeyError. The stream has already been removed, but the HTTP/3 layer still delivers DataReceived. Nothing catches the exception in the UDP server loop, so that worker stops serving HTTP/3 altogether.
  • If the client resets its control stream, the connection is no longer closed with H3_CLOSED_CRITICAL_STREAM, because the HTTP/3 layer never sees the reset.

Since 1.9.0, aioquic reports these events at the HTTP/3 level, so hypercorn doesn't need to look at the QUIC events:

  • Keep passing every QUIC event to handle_event(), and handle the ResetReceived and StopReceived events it returns. They are only sent for requests the application knows about.
  • When the stream is closed, call H3Connection.terminate_request(stream_id). It resets or stops whichever side of the request is still open, and aioquic then drops anything the peer sends on it. That removes the KeyError case and frees aioquic's state for the stream.

This needs aioquic >= 1.9.0 in the h3 extra.

The change to the HTTP/2 websocket sanity tests (adding :protocol) is needed with newer h2 releases. It's unrelated to HTTP/3, so could it go in a separate PR?

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.

2 participants