-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
http: guard against failed sockets creation #13839
Conversation
@nodejs/async_hooks silly question, what do I pass to |
5f7aa8b
to
33dbd50
Compare
lib/_http_agent.js
Outdated
@@ -168,8 +168,10 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/, | |||
// we have a free socket, so use that. | |||
var socket = this.freeSockets[name].shift(); | |||
// Assign the handle a new asyncId and run any init() hooks. | |||
socket._handle.asyncReset(); | |||
socket[async_id_symbol] = socket._handle.getAsyncId(); | |||
if (socket._handle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this check is necessary. It's only the socket creation that's an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
There's still the possibility that createSocket
will be overridden to create sockets that do not have socket._handle.asyncReset
(this is a method that only tcp_wrap
and tls_wrap
have). I should have guarded for that (not simply for the existence of _handle
), but now I don't think that's an interesting use-case.
Ping @nodejs/async_hooks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor things. One is to change usage of nextTick()
the other is a comment about unifying the way tests fail inside a Promise. I don't think I'd consider either a blocker.
lib/_http_agent.js
Outdated
|
||
const asyncId = socket && socket._handle && socket._handle.getAsyncId(); | ||
if (asyncId) { | ||
nextTick(asyncId, emitErr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass null
here and the internal nextTick()
will grab the correct id.
test/parallel/test-http-agent.js
Outdated
}).catch((e) => { | ||
// This is currently the way to fail a test with a Promise | ||
console.error(e); | ||
process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw the fatalError()
code in lib/async_hooks.js
into test/common
(https://github.com/nodejs/node/blob/v8.1.3/lib/async_hooks.js#L54-L68)? This way there's a standardized way of failing. e.g.
const { promiseFatalError } = require('../common'):
Promise.reject(42).catch(promiseFatalError);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh, fancy 🎩!
I like!
New PR coming.
8371f11
to
072082a
Compare
989aa37
to
ae8e5db
Compare
ae8e5db
to
5edafee
Compare
PR-URL: nodejs#13839 Fixes: nodejs#13045 Fixes: nodejs#13831 Refs: nodejs#13352 Refs: nodejs#13548 (comment) Reviewed-By: Trevor Norris <[email protected]>
5edafee
to
4b276e9
Compare
PR-URL: nodejs#13839 Fixes: nodejs#13045 Fixes: nodejs#13831 Refs: nodejs#13352 Refs: nodejs#13548 (comment) Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #13839 Fixes: #13045 Fixes: #13831 Refs: #13352 Refs: #13548 (comment) Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #13839 Fixes: #13045 Fixes: #13831 Refs: #13352 Refs: #13548 (comment) Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #13839 Fixes: #13045 Fixes: #13831 Refs: #13352 Refs: #13548 (comment) Reviewed-By: Trevor Norris <[email protected]>
Fixes: #13045
Fixes: #13831
Ref: #13352
Ref: #13548 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
http,async_hooks