-
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
async_hooks: execute unhandledRejection cb in Promise execution context #37281
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const initHooks = require('./init-hooks'); | ||
const async_hooks = require('async_hooks'); | ||
|
||
if (!common.isMainThread) | ||
common.skip('Worker bootstrapping works differently -> different async IDs'); | ||
|
||
const promiseAsyncIds = []; | ||
const hooks = initHooks({ | ||
oninit(asyncId, type) { | ||
if (type === 'PROMISE') { | ||
promiseAsyncIds.push(asyncId); | ||
} | ||
} | ||
}); | ||
|
||
hooks.enable(); | ||
Promise.reject(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benjamingr I noticed an interesting case. If you just do
Therefore, I tried out setting the context in Let me know your thoughts. |
||
|
||
process.on('unhandledRejection', common.mustCall(() => { | ||
assert.strictEqual(promiseAsyncIds.length, 1); | ||
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]); | ||
})); |
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.
Can we add tests for both cases here?
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 actually manually ran the other case by commenting this line out while running the test case added in this PR. It passed.
However, I guess we can change
ActivityCollector
to not use anoop
function whenondestroy
is not provided. What do you think?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'm not sure why the test would need to use
ActivityCollector
, or be intest/async-hooks
-- a lot of async_hooks tests that don't make use of the special features that that subdirectory has are just intest/parallel
.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 see. What are these "special features" out of curiosity?
Also, if I just assumed initHooks had convenient methods when dealing with async hooks. What is otherwise the purpose?
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.
Things like
ActivityCollector
, and the rest that’s inasync-hooks/init-hooks.js
andasync-hooks/hook-checks.js
.They do, but it’s not like you have to use them. At least for the test here, the difference to using async hooks directly seems to be relatively small.