Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: better error message for socket disconnect #18989

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember if we're keeping this intentionally with the old errors or if this needs to be converted to use internal/errors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to switch to the internal/errors and override the code for now. It is not a strong opinion though and I am fine with keeping it as it is for now as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I’m going to leave this out of this PR.

I don’t think I’m a fan of changing the code property of exactly those errors where we always provided one, though.

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