fix: handle invalid HTTP/2 headers gracefully (#4356)#5077
Open
fix: handle invalid HTTP/2 headers gracefully (#4356)#5077
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5077 +/- ##
==========================================
- Coverage 93.10% 93.08% -0.03%
==========================================
Files 110 110
Lines 35770 35853 +83
==========================================
+ Hits 33303 33372 +69
- Misses 2467 2481 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
webcarrot
reviewed
Apr 20, 2026
Comment on lines
+534
to
+542
| // An error here means the server sent invalid HTTP/2 headers | ||
| // (e.g., HTTP/1 headers like "http2-settings"). This is a server error. | ||
| // We destroy the socket/session and error the request so the client | ||
| // can retry with a new connection. | ||
| util.errorRequest(client, request, err) | ||
| const socket = session[kSocket] | ||
| session.destroy(err) | ||
| util.destroy(socket, err) | ||
| return false |
There was a problem hiding this comment.
I don’t know how h2 works, but did this cause other "valid", ongoing requests that use the same socket/session to be interrupted?
When session.request() throws synchronously due to invalid HTTP/2 headers (e.g., duplicate headers like 'content-type' and 'Content-Type'), the error was not being caught, causing an uncaught exception. The fix wraps all session.request() calls with try-catch blocks. When an error is caught, only the request is errored (via util.errorRequest) and the function returns false. The session is not destroyed because the error is caused by the client sending invalid headers, not the server. This allows the client to continue using the same session for subsequent requests, and the error is properly caught by user code. Closes #4356
dcf9d03 to
500eb60
Compare
metcoder95
reviewed
Apr 21, 2026
Member
metcoder95
left a comment
There was a problem hiding this comment.
Tests seems, failing; rest lgtm
Member
Author
|
@metcoder95 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.
When session.request() throws synchronously due to invalid HTTP/2 headers (e.g., duplicate headers like "content-type" and "Content-Type"), the error was not being caught, causing an uncaught exception.
The fix wraps all session.request() calls with try-catch blocks. When an error is caught, only the request is errored (via util.errorRequest) and the function returns false. The session is not destroyed because the error is caused by the client sending invalid headers, not the server.
This allows the client to continue using the same session for subsequent requests, and the error is properly caught by user code.
Closes #4356