Skip to content

fix(utils): cancel late HTTP/2 response bodies - #416

Open
owendavidgoode wants to merge 2 commits into
honojs:mainfrom
owendavidgoode:fix/http2-late-response-cancellation
Open

owendavidgoode wants to merge 2 commits into
honojs:mainfrom
owendavidgoode:fix/http2-late-response-cancellation

Conversation

@owendavidgoode

Copy link
Copy Markdown

HTTP/2 response bodies returned after the client closes its stream or session are not cancelled. Http2ServerResponse exposes the transport lifecycle through its backing stream, so checking the wrapper's destroyed property misses the already-closed connection.

Check the backing HTTP/2 stream before starting the reader pump and cancel the reader when that stream is already closed or destroyed. This covers native and cached responses, including a disconnect during the native response's pre-read tick.

Related to #411 and complementary to #412. The HTTP/2 regression still fails with #412's exact production changes; this patch does not include or replace its HTTP/1 fix.

Validation:

  • Real HTTP/2 stream reset and session-close cases for native and cached responses.
  • A disconnect during the native pre-read tick, with timer interception limited to that interval and listener settlement checked.
  • Native and cached responses cancelled after the client receives a prefix and resets the stream.
  • Normal-completion controls that preserve response bytes without cancellation.
  • Five failure cases reproduced on main and on fix(listener): cancel the response body when the client has already disconnected #412; the two normal-completion controls pass.
  • Listener and stream-utility suites: 64 tests pass on Node 20.20.2, 22.23.4, and 24.21.0.
  • Full suite: 512 tests pass on Node 24.21.0. The earlier 510-test suite also passed on Node 20 and 22 before the test-only hardening.
  • Formatting, lint, type checking, build, and package validation pass.

AI assistance was used for implementation and review. All fixtures are synthetic and derived from public source and runtime contracts.

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.

1 participant