Skip to content

Commit 7d9eb17

Browse files
himself65targos
authored andcommitted
http2: destroy when settingsFn throws an error
http2.connect should call destroy when init fails. PR-URL: #28908 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent f4abf17 commit 7d9eb17

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
@@ -976,7 +976,13 @@ class Http2Session extends EventEmitter {
976976
if (socket.connecting) {
977977
const connectEvent =
978978
socket instanceof tls.TLSSocket ? 'secureConnect' : 'connect';
979-
socket.once(connectEvent, setupFn);
979+
socket.once(connectEvent, () => {
980+
try {
981+
setupFn();
982+
} catch (error) {
983+
socket.destroy(error);
984+
}
985+
});
980986
} else {
981987
setupFn();
982988
}

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)