fix(h2): prevent uncaughtException from onHttp2SocketError accessing undefined kClient#5546
Open
mcollina wants to merge 3 commits into
Open
fix(h2): prevent uncaughtException from onHttp2SocketError accessing undefined kClient#5546mcollina wants to merge 3 commits into
mcollina wants to merge 3 commits into
Conversation
…undefined kClient The onHttp2SocketError handler accesses this[kClient] where this is the socket, but kClient is only stored on the session (session[kClient]), never on the socket. This causes a TypeError when the error handler is invoked, which becomes an uncaughtException. Fix by routing through this[kHTTP2Session]?.[kClient] instead. Also wraps stream.destroy(err) in util.destroy and onHttp2SessionEnd in try-catch, since http2-managed sockets throw ERR_HTTP2_NO_SOCKET_MANIPULATION on direct destroy() calls. Fixes #5525
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5546 +/- ##
=======================================
Coverage 93.45% 93.45%
=======================================
Files 110 110
Lines 37376 37416 +40
=======================================
+ Hits 34928 34967 +39
- Misses 2448 2449 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ket close Verifies that aborting an in-flight HTTP/2 request followed by the socket closing does not trigger an uncaughtException. This exercises the onHttp2SocketError fix where kClient must be accessed through the session rather than directly on the socket.
Member
Author
|
The underlying |
Http2Session is a plain EventEmitter and never emits 'end', so this listener could never fire.
trivikr
reviewed
Jul 11, 2026
Comment on lines
+1105
to
+1107
| after(() => { | ||
| server.close() | ||
| }) |
Member
There was a problem hiding this comment.
Use t.after
Suggested change
| after(() => { | |
| server.close() | |
| }) | |
| t.after(() => { | |
| server.close() | |
| }) |
Ditto at other places.
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.
Root Cause
In
client-h2.js,onHttp2SocketErroraccessesthis[kClient]wherethisis the socket. However,kClientis only stored on the session (session[kClient] = client), never on the socket. Sothis[kClient]isundefined, and callingthis[kClient][kOnError](err)throws aTypeError. This thrown error inside the 'error' event handler becomes an uncaughtException.Changes
onHttp2SocketError— Route throughthis[kHTTP2Session]?.[kClient]instead ofthis[kClient]util.destroy— Wrapstream.destroy(err)in try-catch (http2-managed sockets throw on directdestroy())onHttp2SessionEnd— Wraputil.destroy(this[kSocket], err)in try-catch (same reason)Testing
All 1421 existing tests pass (1418 pass, 3 skipped).
Fixes #5525