Skip to content

fix: retry refused HTTP/2 streams - #5598

Open
mcollina wants to merge 1 commit into
mainfrom
fix/http2-refused-stream-retry
Open

fix: retry refused HTTP/2 streams#5598
mcollina wants to merge 1 commit into
mainfrom
fix/http2-refused-stream-retry

Conversation

@mcollina

Copy link
Copy Markdown
Member

This relates to...

HTTP/2 peers can reject an unprocessed stream with RST_STREAM(REFUSED_STREAM). Node.js surfaces this as the generic ERR_HTTP2_STREAM_ERROR, and Undici previously failed the request without considering the retry-safe HTTP/2 reset code.

Rationale

RFC 9113 section 8.7 permits clients to retry a request rejected with REFUSED_STREAM, including non-idempotent requests, because the peer asserts that no application processing occurred. It also says clients should not automatically retry the same request more than once.

Changes

Features

N/A

Bug Fixes

  • Detect NGHTTP2_REFUSED_STREAM using stream.rstCode before response headers are exposed.
  • Retry the request once on the existing HTTP/2 session.
  • Restrict transparent retries to replayable bodies: no body, Buffer, or Blob.
  • Preserve the numeric reset code as error.http2ErrorCode when an error is ultimately exposed.
  • Add regression coverage for concurrent streams, buffered POST bodies, the one-retry limit, streaming bodies, and other reset codes.

Breaking Changes and Deprecations

None.

Status

Validation:

  • npm run test:h2:core — 96 passed
  • npm run test:h2:fetch — 11 passed
  • npx eslint lib/dispatcher/client-h2.js test/http2-refused-stream.js
  • Commit hook npm run lint

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina requested a review from trivikr July 27, 2026 16:15
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.49%. Comparing base (21a8e1e) to head (b87e26f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5598      +/-   ##
==========================================
+ Coverage   93.47%   93.49%   +0.01%     
==========================================
  Files         110      110              
  Lines       38238    38327      +89     
==========================================
+ Hits        35744    35833      +89     
  Misses       2494     2494              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina
mcollina requested a review from metcoder95 July 28, 2026 06:41
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.

4 participants