Repository navigation
executionAsyncId() reports parent context ID in new Promise(fn) function #37407
Description
Activity
Here's a TAP-emitting test that you can use to comb through these. Note that the "expect" value seems to be the thing that's mistaken in the current node master branch, which is a huge step in the right direction!
https://github.com/proxy/gist.github.com/isaacs/c8d15def6869ff738c69037155dda2c2
I think this might be due to the fact that a
new Promise()'s fn callback is called synchronously. Therefore, the execution context didn't change.Reacted by Benjamin Gruenbaum- addedasync_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.
on Feb 16, 2021 With the existing Promise Hooks types, I don't see any information/hooks given out to the embedder as to start and end points of the callback provided to the
Promise. I'd be interested too in knowing if this is possible.@sajal50 is correct. The function passed to
new Promise()is called sync therefore it has the same eId as it is the same async operation.new Promise()creates/inits a new asyncId which should be signaled via the init hook and is that one you should see in the then callback.In the end this is quite similar then callback based APIs, e.g. in
fs.readFile('file', cb))the eId withinfs.readFileis the same as for the caller.fs.readFilecreates a new id which is active in the callback.- changed the title
[-]executionAsyncId() incorrectly reports parent context ID in `new Promise(fn)` function[/-][+]executionAsyncId() ~incorrectly~ reports parent context ID in `new Promise(fn)` function[/+]on Feb 19, 2021 - changed the title
[-]executionAsyncId() ~incorrectly~ reports parent context ID in `new Promise(fn)` function[/-][+]executionAsyncId() reports parent context ID in `new Promise(fn)` function[/+]on Feb 19, 2021 Hm. That does make sense. It's a bit weird that the executionAsyncId changes between the throw and the catch there, but anywhere you put that boundary is going to be strange. And since the executionAsyncId refers to the promise itself in the error/rejection handler, that's fine for making
async-hook-domainswork properly.
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
The
executionAsyncIdwithin thePromisefunction should be that of the Promise itself, rather than the parent context.What do you see instead?
Additional information
Possibly related to #26794, not sure.
Note that the Promise constructor callback does report the proper executionAsyncId when the Promise is created in the context of a Promise chain.