From 7b3d2dad4863fb1878dbb5c83b1d437ebd728ab7 Mon Sep 17 00:00:00 2001 From: himself65 Date: Wed, 31 Jul 2019 22:20:13 +0800 Subject: [PATCH 1/2] http2: destroy when call settingsFn throw an error --- lib/internal/http2/core.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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(); } From 43454d48482ac7c60f04d5656f6d4f0355ed6eb3 Mon Sep 17 00:00:00 2001 From: himself65 Date: Wed, 31 Jul 2019 22:24:28 +0800 Subject: [PATCH 2/2] test: http2.connect call destroy when init fail --- test/parallel/test-http2-connect.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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';