Skip to content

fix(http2): reject websocket upgrades on non-200 responses#5072

Merged
mcollina merged 1 commit intonodejs:mainfrom
trivikr:h2-websocket-upgrade-crash
Apr 20, 2026
Merged

fix(http2): reject websocket upgrades on non-200 responses#5072
mcollina merged 1 commit intonodejs:mainfrom
trivikr:h2-websocket-upgrade-crash

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented Apr 20, 2026

This relates to...

Fixes: #5063

Rationale

client.upgrade() over HTTP/2 currently asserts when a websocket extended CONNECT request receives a non-200 response.

That assertion escapes the normal request error path and crashes the process instead of rejecting the upgrade promise.

Changes

  • replace the upgrade-path assertion with a normal SocketError('bad upgrade') abort in the upgrade handler
  • preserve existing successful upgrade behavior for H1 (101) and H2 (200)

Features

N/A

Bug Fixes

  • reject HTTP/2 websocket upgrades with non-200 responses instead of throwing an uncaught assertion
  • align H2 bad-upgrade handling with the existing upgrade error semantics used elsewhere in undici

Breaking Changes and Deprecations

N/A

Status

Assisted-by: openai:gpt-5.4
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (f6c5dda) to head (e93cff5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5072   +/-   ##
=======================================
  Coverage   93.10%   93.10%           
=======================================
  Files         110      110           
  Lines       35799    35805    +6     
=======================================
+ Hits        33329    33337    +8     
+ Misses       2470     2468    -2     

☔ View full report in Codecov by Sentry.
📢 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.

@trivikr trivikr changed the title fix: reject h2 websocket upgrades on non-200 responses fix(http2): reject websocket upgrades on non-200 responses Apr 20, 2026
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit c7a2901 into nodejs:main Apr 20, 2026
34 of 35 checks passed
@trivikr trivikr deleted the h2-websocket-upgrade-crash branch April 21, 2026 15:19
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.

H2 websocket upgrade crashes process on non-200 response instead of rejecting client.upgrade()

3 participants