-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
async_hooks: triggerAsyncId can be undefined #14387
Conversation
@nodejs/async_hooks @AndreasMadsen please verify. I do not claim this is the right fix or what other consequences this fix could have, but it solves the problem here. |
Side note: the commit does not pass |
This problem was likely introduced in #14026. |
We need to find the cause for why |
@AndreasMadsen the way 'shot' works is by piggypacking on core, and it does not allocate a full socket. https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L281 is expecting to have a real socket, but it has not in this case. I can write that test and default the value of that symbol to This change avoid all the crashes, at the cost of reporting bad data, why is it wrong? |
I agree. I suggested to @trevnorris that we skipped the entire assert in
Sounds reasonable. As far as I have seen the only two sources of error we have seen after |
I'll work on the other PR to null things in |
lib/internal/process/next_tick.js
Outdated
@@ -281,7 +281,7 @@ function setupNextTick() { | |||
if (process._exiting) | |||
return; | |||
|
|||
if (triggerAsyncId === null) { | |||
if (triggerAsyncId === null || triggerAsyncId === undefined) { |
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 belive !Number.isSafeInteger(triggerAsyncId ) || triggerAsyncId < 0
is the "preferred" test
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.
If that is actually a valid code path
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.
If not, double equals would be preferred to combine both checks.
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.
Could be simplified to just if (triggerAsyncId == null) {
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.
heh... sorry, just spotted @mscdex's identical comment ;-)
@trevnorris what do you think of this? |
Change the statement to |
@trevnorris if you prefer this over #14389, I'll patch it right now. |
@trevnorris ... I'm still trying to determine if this is the only one :-) need more coffee. If @mcollina is happy with it and it addresses the immediate need, then +1 |
I'm happy. I'll add a test also for #14368, so we don't regress on that as well. |
@trevnorris @addaleax @jasnell please review. I've included also a fix for: #14368. |
const res = new Response(); | ||
const ws = new Writable({ | ||
write: common.mustCall((chunk, encoding, callback) => { | ||
assert(chunk.toString().match(/hello world/)); |
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.
Why this and not assert.strictEqual(chunk.toString(), 'hello world')
?
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.
the chunk contains a full HTTP response, which for brevity I did not want to include. common.mustCall
it's also sufficient to validate the test on its own.
} | ||
|
||
server.listen(0, common.mustCall(() => { | ||
http.get('http://localhost:' + server.address().port) |
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.
nit...
http.get(`http://localhost:${server.address().port}`);
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.
done
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.
Couple of nits but LGTM
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.
thanks for the changes
Fixes: #14386 Fixes: #14381 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Fixes: #14368 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Uh oh, these work just fine on
|
Hmmmm, that might be flakey. I can't repo it now. |
Fixes: #14386 Fixes: #14381 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Fixes: #14368 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Stress on linuxONE: https://ci.nodejs.org/job/node-stress-single-test/1336/nodes=rhel72-s390x/ |
I stress tested against master locally. It's flaky: $ tools/test.py -j92 --repeat 920 test/async-hooks/test-tlswrap.js
=== release test-tlswrap ===
Path: async-hooks/test-tlswrap
assert.js:43
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: Checking invocations at stage "client: when client destroyed":
Called "before" 2 time(s), but expected 3 invocation(s).
at checkHook (/Users/trott/io.js/test/async-hooks/hook-checks.js:51:14)
at Array.forEach (<anonymous>)
at checkInvocations (/Users/trott/io.js/test/async-hooks/hook-checks.js:28:44)
at tick1 (/Users/trott/io.js/test/async-hooks/test-tlswrap.js:93:5)
at Immediate.ontick (/Users/trott/io.js/test/async-hooks/tick.js:7:37)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
Command: out/Release/node /Users/trott/io.js/test/async-hooks/test-tlswrap.js Probably race condition. The comment around before line 93 (where the test fails) kind of suggests that too: // TODO: why is client not destroyed here even after 5 ticks?
// or could it be that it isn't actually destroyed until
// the server is closed? |
Fixes: #14386 Fixes: #14381 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Fixes: #14368 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #15454 Ref: #14387 Ref: #14722 Ref: #14717 Ref: #15448 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
PR-URL: nodejs/node#15454 Ref: nodejs/node#14387 Ref: nodejs/node#14722 Ref: nodejs/node#14717 Ref: nodejs/node#15448 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
PR-URL: nodejs/node#15454 Ref: nodejs/node#14387 Ref: nodejs/node#14722 Ref: nodejs/node#14717 Ref: nodejs/node#15448 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Fixes: #14386
Fixes: #14381
Fixes: #14368
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks