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: add host and port info to ECONNRESET errors #7476

Closed

Conversation

jfromaniello
Copy link
Contributor

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

TLS

Description of change

Add more information (host, port, path) to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

@nodejs-github-bot nodejs-github-bot added the tls Issues and PRs related to the tls subsystem. label Jun 29, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Jun 29, 2016

Is there potential to reuse util._exceptionWithHostPort() here?

const net = require('net');

net.createServer(c => {
setTimeout(() => c.end(), 300);
Copy link
Member

Choose a reason for hiding this comment

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

Is the timeout necessary?

@jfromaniello
Copy link
Contributor Author

@santigimeno thanks for all the feedback in the test case :)

@cjihrig good point! I will try

@jfromaniello
Copy link
Contributor Author

@cjihrig I can't find a way to call util._exceptionWithHostPort without getting this error:

util.js:1003
  var errname = uv.errname(err);
                   ^

Error: err >= 0
    at Error (native)
    at Object.exports._errnoException (util.js:1003:20)
    at Object.exports._exceptionWithHostPort (util.js:1030:20)
    at TLSSocket.onHangUp (_tls_wrap.js:1094:21)
    at TLSSocket.g (events.js:286:16)
    at emitNone (events.js:91:20)
    at TLSSocket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:926:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I see this function is being used in two places, the first argument being the error returned from bind.

@jasnell jasnell added semver-minor PRs that contain new features and should be released in the next minor version. error-handling labels Jun 29, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Jun 29, 2016

Ah, sorry, it expects an error code, and we're creating an error object here. Carry on :-)

@jasnell
Copy link
Member

jasnell commented Jun 29, 2016

Don't have any particular issue with this but I'd like to get some more opinions. @nodejs/ctc

@indutny
Copy link
Member

indutny commented Jun 30, 2016

LGTM

https.get(`https://localhost:${port}`)
.on('error', common.mustCall(e => {
assert.equal(e.host, 'localhost');
assert.equal(e.port, port);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use assert.strictEqual here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I am not sure why it ends up being an string at _tls_wrap.connect

@bnoordhuis
Copy link
Member

It would be nice to have test coverage for options.socket and options.path as well.

@jfromaniello
Copy link
Contributor Author

@bnoordhuis thank you very much for the feedback. I added tests for options.socket and options.path as well.

@jfromaniello
Copy link
Contributor Author

I did some changes to the PR to include the address when using options.socket.

lib/_tls_wrap.js Outdated
};
}
}

Copy link
Member

Choose a reason for hiding this comment

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

This adds a closure and makes the closure for onHangup() bigger (i.e., more memory, more gc'ing.) I would like to avoid that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis ok, I am going to revert to what I had before, but I won't be able to handle the options.socket case properly, because it seems that socket.remoteAddress is deleted before the end event.

@jfromaniello
Copy link
Contributor Author

@bnoordhuis updated with your suggestion. thanks again

assert.strictEqual(e.port, undefined);
assert.strictEqual(e.host, undefined);
server.close();
}, 'the request must emit error'));
Copy link
Member

Choose a reason for hiding this comment

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

common.mustCall doesn't take a string as its second argument.

@mscdex mscdex added errors Issues and PRs related to JavaScript errors originated in Node.js core. and removed error-handling labels Oct 28, 2016
@jasnell
Copy link
Member

jasnell commented Jan 6, 2017

Looks like this one slipped through the cracks

@jasnell
Copy link
Member

jasnell commented Jan 6, 2017

@jfromaniello
Copy link
Contributor Author

Is there anything I can help with to get this one and #7498 merged? Thanks

Copy link
Contributor

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

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

looks like there are enough approvals for this to land if tests are happy.

@fhinkel
Copy link
Member

fhinkel commented Mar 26, 2017

It's semver-minor. Can we just land it?

@jasnell
Copy link
Member

jasnell commented Mar 26, 2017

Yep. It's on my list to review on Monday but if you'd like to go ahead, go for it..

@tniessen
Copy link
Member

tniessen commented Jun 14, 2017

Last CI was half a year ago, I will land this today if CI passes: https://ci.nodejs.org/job/node-test-pull-request/8655/

Edit: Retrying osx only: https://ci.nodejs.org/job/node-test-commit-osx/10491/

tniessen pushed a commit that referenced this pull request Jun 14, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
@tniessen
Copy link
Member

tniessen commented Jun 14, 2017

CI is green, landed in 3ee3732! Thank you for your contribution! 🎉

@tniessen tniessen closed this Jun 14, 2017
addaleax pushed a commit that referenced this pull request Jun 17, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
@addaleax addaleax mentioned this pull request Jun 17, 2017
addaleax pushed a commit that referenced this pull request Jun 21, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
addaleax pushed a commit that referenced this pull request Jun 24, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
rvagg pushed a commit that referenced this pull request Jun 29, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
addaleax pushed a commit that referenced this pull request Jul 11, 2017
Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: #7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
@gibfahn
Copy link
Member

gibfahn commented Jan 15, 2018

Release team decided not to land on v6.x, if you disagree let us know.

@bnoordhuis
Copy link
Member

@gibfahn What was the motivation? It's pretty useful.

@gibfahn
Copy link
Member

gibfahn commented Jan 18, 2018

@gibfahn What was the motivation? It's pretty useful.

IIRC the motivation was that this changes an error message, which could break people. If that's not true we can reconsider.

@jfromaniello
Copy link
Contributor Author

IIRC the motivation was that this changes an error message, which could break people. If that's not true we can reconsider.

It is not true, it doesn't change the error message. It just add new properties to the error object:

  • error.path
  • error.host
  • error.port
  • error.localAddress

This is currently being done in other places with the same property names (I can't remember now where) and I think is very useful to diagnose issues with tcp connections.

@gibfahn
Copy link
Member

gibfahn commented Jan 19, 2018

cc/ @nodejs/lts let's reconsider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-minor PRs that contain new features and should be released in the next minor version. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.