Skip to content

Commit

Permalink
http2: destroy when settingsFn throws an error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
himself65 authored and Trott committed Aug 2, 2019
1 parent 36864a6 commit 2b03e1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/internal/http2/core.js
Expand Up @@ -972,7 +972,13 @@ class Http2Session extends EventEmitter {
if (socket.connecting) { if (socket.connecting) {
const connectEvent = const connectEvent =
socket instanceof tls.TLSSocket ? 'secureConnect' : 'connect'; socket instanceof tls.TLSSocket ? 'secureConnect' : 'connect';
socket.once(connectEvent, setupFn); socket.once(connectEvent, () => {
try {
setupFn();
} catch (error) {
socket.destroy(error);
}
});
} else { } else {
setupFn(); setupFn();
} }
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-http2-connect.js
Expand Up @@ -69,6 +69,20 @@ const { connect: netConnect } = require('net');
connect(authority).on('error', () => {}); 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) // Check for error for an invalid protocol (not http or https)
{ {
const authority = 'ssh://localhost'; const authority = 'ssh://localhost';
Expand Down

0 comments on commit 2b03e1d

Please sign in to comment.