Skip to content

Commit eda7021

Browse files
addaleaxapapirovski
authored andcommitted
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: #18989 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 1ebd966 commit eda7021

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/_tls_wrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ function onConnectSecure() {
10741074
this.emit('secureConnect');
10751075
}
10761076

1077-
// Uncork incoming data
10781077
this.removeListener('end', onConnectEnd);
10791078
}
10801079

@@ -1083,7 +1082,8 @@ function onConnectEnd() {
10831082
if (!this._hadError) {
10841083
const options = this[kConnectOptions];
10851084
this._hadError = true;
1086-
const error = new Error('socket hang up');
1085+
const error = new Error('Client network socket disconnected before ' +
1086+
'secure TLS connection was established');
10871087
error.code = 'ECONNRESET';
10881088
error.path = options.path;
10891089
error.host = options.host;

test/parallel/test-tls-empty-sni-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ const server = tls.createServer(options, (c) => {
2929
}, common.mustNotCall());
3030

3131
c.on('error', common.mustCall((err) => {
32-
assert(/socket hang up/.test(err.message));
32+
assert(/Client network socket disconnected/.test(err.message));
3333
}));
3434
}));

test/parallel/test-tls-sni-option.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ process.on('exit', function() {
175175
]);
176176
assert.deepStrictEqual(clientResults, [true, true, true, false, false]);
177177
assert.deepStrictEqual(clientErrors, [
178-
null, null, null, null, 'socket hang up'
178+
null, null, null, null,
179+
'Client network socket disconnected before secure TLS ' +
180+
'connection was established'
179181
]);
180182
assert.deepStrictEqual(serverErrors, [
181183
null, null, null, null, 'Invalid SNI context'

0 commit comments

Comments
 (0)