http2: destroy when settingsFn throws an error

http2.connect should call destroy when init fails.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
himself65 2019-07-31 22:20:13 +08:00 committed by Rich Trott
parent 36864a60fa
commit 2b03e1d0a5
2 changed files with 21 additions and 1 deletions

View File

@ -972,7 +972,13 @@ class Http2Session extends EventEmitter {
if (socket.connecting) {
const connectEvent =
socket instanceof tls.TLSSocket ? 'secureConnect' : 'connect';
socket.once(connectEvent, setupFn);
socket.once(connectEvent, () => {
try {
setupFn();
} catch (error) {
socket.destroy(error);
}
});
} else {
setupFn();
}

View File

@ -69,6 +69,20 @@ const { connect: netConnect } = require('net');
connect(authority).on('error', () => {});
}
// Check for error for init settings error
{
createServer(function() {
connect(`http://localhost:${this.address().port}`, {
settings: {
maxFrameSize: 1 // An incorrect settings
}
}).on('error', expectsError({
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: RangeError
}));
});
}
// Check for error for an invalid protocol (not http or https)
{
const authority = 'ssh://localhost';