Skip to content

Commit

Permalink
tls: better error message for socket disconnect
Browse files Browse the repository at this point in the history
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: nodejs#18989
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
addaleax authored and MayaLekova committed May 8, 2018
1 parent d118e77 commit a4b7141
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,6 @@ function onConnectSecure() {
this.emit('secureConnect');
}

// Uncork incoming data
this.removeListener('end', onConnectEnd);
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-empty-sni-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}));
}));
4 changes: 3 additions & 1 deletion test/parallel/test-tls-sni-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a4b7141

Please sign in to comment.