fix: native WebSocket over H2 server after undici import#4990
Open
fix: native WebSocket over H2 server after undici import#4990
Conversation
Importing undici v8 overwrites the legacy global dispatcher
(Symbol.for('undici.globalDispatcher.1')) used by Node.js's bundled
undici. The new Agent defaults to allowH2: true, causing ALPN to
negotiate h2. Undici v8's fetch has a fallback
(dispatchWithProtocolPreference) that retries with HTTP/1.1 when
Extended CONNECT is unavailable, but the bundled undici does not.
Fix Dispatcher1Wrapper.dispatch() to force allowH2: false for upgrade
requests, since legacy consumers cannot handle the H2 WebSocket
fallback.
Fixes: #4989
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Member
Author
|
@cristianmadularu please test this |
Is it released? If not, how could I reference it from my packages.json? |
KhafraDev
requested changes
Apr 7, 2026
Member
KhafraDev
left a comment
There was a problem hiding this comment.
Test is failing and it'll only work on node version that bundle undici v7.
Legacy (v1) consumers (like Node.js's bundled undici on Node 22) do not support HTTP/2. Force allowH2: false in Dispatcher1Wrapper so that the v1 global dispatcher always uses HTTP/1.1. Also add NODE_TLS_REJECT_UNAUTHORIZED for the regression test since native WebSocket uses the bundled dispatcher without rejectUnauthorized override. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4990 +/- ##
==========================================
- Coverage 92.94% 92.87% -0.07%
==========================================
Files 110 110
Lines 35773 35794 +21
==========================================
- Hits 33249 33244 -5
- Misses 2524 2550 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
@KhafraDev ptal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Importing undici v8 overwrites the legacy global dispatcher
(Symbol.for('undici.globalDispatcher.1')) used by Node.js's bundled
undici. The new Agent defaults to allowH2: true, causing ALPN to
negotiate h2. Undici v8's fetch has a fallback
(dispatchWithProtocolPreference) that retries with HTTP/1.1 when
Extended CONNECT is unavailable, but the bundled undici does not.
Fix Dispatcher1Wrapper.dispatch() to force allowH2: false for legacy consumers that cannot handle the H2 WebSocket fallback.
Fixes: #4989