diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index ec720da71ee008..fca37ae2b0812a 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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(); } diff --git a/test/parallel/test-http2-connect.js b/test/parallel/test-http2-connect.js index a1291e3be956e1..4569905eac9be1 100644 --- a/test/parallel/test-http2-connect.js +++ b/test/parallel/test-http2-connect.js @@ -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';