From eda702104b3447dd56dc635565b4c88b0e04685a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 25 Feb 2018 21:43:23 +0100 Subject: tls: better error message for socket disconnect The error emitted when a connection is closed before the TLS handshake completes seemed rather unspefic by just saying `socket hang up`. Use a more verbose message, that also indicates that this is a purely client-side error, and remove a misleading comment. PR-URL: https://github.com/nodejs/node/pull/18989 Reviewed-By: Luigi Pinca Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- lib/_tls_wrap.js | 4 ++-- test/parallel/test-tls-empty-sni-context.js | 2 +- test/parallel/test-tls-sni-option.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index b3c48b950c..c472564270 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1074,7 +1074,6 @@ function onConnectSecure() { this.emit('secureConnect'); } - // Uncork incoming data this.removeListener('end', onConnectEnd); } @@ -1083,7 +1082,8 @@ function onConnectEnd() { if (!this._hadError) { const options = this[kConnectOptions]; this._hadError = true; - const error = new Error('socket hang up'); + const error = new Error('Client network socket disconnected before ' + + 'secure TLS connection was established'); error.code = 'ECONNRESET'; error.path = options.path; error.host = options.host; diff --git a/test/parallel/test-tls-empty-sni-context.js b/test/parallel/test-tls-empty-sni-context.js index 9a8e3449f0..48f9a52463 100644 --- a/test/parallel/test-tls-empty-sni-context.js +++ b/test/parallel/test-tls-empty-sni-context.js @@ -29,6 +29,6 @@ const server = tls.createServer(options, (c) => { }, common.mustNotCall()); c.on('error', common.mustCall((err) => { - assert(/socket hang up/.test(err.message)); + assert(/Client network socket disconnected/.test(err.message)); })); })); diff --git a/test/parallel/test-tls-sni-option.js b/test/parallel/test-tls-sni-option.js index d4b6a8e190..b3a5adb47c 100644 --- a/test/parallel/test-tls-sni-option.js +++ b/test/parallel/test-tls-sni-option.js @@ -175,7 +175,9 @@ process.on('exit', function() { ]); assert.deepStrictEqual(clientResults, [true, true, true, false, false]); assert.deepStrictEqual(clientErrors, [ - null, null, null, null, 'socket hang up' + null, null, null, null, + 'Client network socket disconnected before secure TLS ' + + 'connection was established' ]); assert.deepStrictEqual(serverErrors, [ null, null, null, null, 'Invalid SNI context' -- cgit v1.2.3