Skip to content

fix(websocket): fallback to HTTP/1.1 when H2 CONNECT is unavailable#4966

Merged
mcollina merged 3 commits intomainfrom
fix/websocket-http1-fallback
Apr 3, 2026
Merged

fix(websocket): fallback to HTTP/1.1 when H2 CONNECT is unavailable#4966
mcollina merged 3 commits intomainfrom
fix/websocket-http1-fallback

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Apr 3, 2026

Summary

Fix websocket handshakes when TLS negotiates HTTP/2 but the server does not advertise RFC 8441 extended CONNECT support.

Instead of failing immediately, retry the opening handshake on a fresh HTTP/1.1-only connection. This preserves websocket support for allowHTTP1 HTTP/2 servers and other deployments that only support websocket upgrade over HTTP/1.1.

Changes

  • add a regression test for websocket fallback to HTTP/1.1 upgrade
  • retry websocket handshakes over HTTP/1.1 when H2 extended CONNECT is unavailable
  • plumb the HTTP/1.1-only retry through Agent and proxy TLS connectors

Testing

  • npx eslint lib/dispatcher/client.js lib/dispatcher/proxy-agent.js lib/dispatcher/agent.js lib/web/fetch/index.js test/websocket/opening-handshake.js
  • node --test test/websocket/opening-handshake.js

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 96.58120% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.96%. Comparing base (490cbc6) to head (92c7b8f).

Files with missing lines Patch % Lines
lib/web/fetch/index.js 95.95% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4966   +/-   ##
=======================================
  Coverage   92.95%   92.96%           
=======================================
  Files         111      111           
  Lines       35821    35864   +43     
=======================================
+ Hits        33299    33342   +43     
  Misses       2522     2522           

☔ 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.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
await planner.completed
})

test('WebSocket falls back to HTTP/1.1 upgrade when H2 extended CONNECT is unavailable', async (t) => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pimterry PTAL

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Copy link
Copy Markdown
Member

@pimterry pimterry left a comment

Choose a reason for hiding this comment

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

I'm not super familiar with the Undici internals, but they look roughly sensible to me - the test definitely looks like the right end behaviour 👍

@mcollina mcollina merged commit 58ef10d into main Apr 3, 2026
31 of 33 checks passed
@mcollina mcollina deleted the fix/websocket-http1-fallback branch April 3, 2026 20:51
@github-actions github-actions bot mentioned this pull request Apr 4, 2026
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