Skip to content

Commit 2b03e1d

Browse files
himself65Trott
authored andcommitted
http2: destroy when settingsFn throws an error
http2.connect should call destroy when init fails. PR-URL: #28908 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 36864a6 commit 2b03e1d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/internal/http2/core.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,13 @@ class Http2Session extends EventEmitter {
972972
if (socket.connecting) {
973973
const connectEvent =
974974
socket instanceof tls.TLSSocket ? 'secureConnect' : 'connect';
975-
socket.once(connectEvent, setupFn);
975+
socket.once(connectEvent, () => {
976+
try {
977+
setupFn();
978+
} catch (error) {
979+
socket.destroy(error);
980+
}
981+
});
976982
} else {
977983
setupFn();
978984
}

test/parallel/test-http2-connect.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ const { connect: netConnect } = require('net');
6969
connect(authority).on('error', () => {});
7070
}
7171

72+
// Check for error for init settings error
73+
{
74+
createServer(function() {
75+
connect(`http://localhost:${this.address().port}`, {
76+
settings: {
77+
maxFrameSize: 1 // An incorrect settings
78+
}
79+
}).on('error', expectsError({
80+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
81+
type: RangeError
82+
}));
83+
});
84+
}
85+
7286
// Check for error for an invalid protocol (not http or https)
7387
{
7488
const authority = 'ssh://localhost';

0 commit comments

Comments
 (0)