-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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.currentId() sometimes reports the wrong id during PromiseReactionJob #13427
Comments
/cc @nodejs/async_hooks |
I investigated the issue, it is because |
So here is a conundrum, how can we make the following work without having PromiseHooks for const p = new Promise((resolve) => resolve(1));
p.then(function () {
async_hooks.currentId();
}); /cc @matthewloring |
Since Node always runs the microtask queue manually, one thing that we could do is to only AsyncWrap the entire queue; that will give you slightly inconsistent async ids, because multiple Promises might share one, but since one can’t really attach any meaning to the ids that one didn’t witness I’ll try to get some code together for that. I think I’ve already said this a couple times, but I really would like to not use |
The user can still listen to just
Hmm, how expensive are the internal fields? Could we consistently have a cheap If |
@addaleax I don't think I fully understand your suggestion but the idea of slightly inconsistent ids is scary. When you say AsyncWrap the entire queue do you mean fire a single before/after event for all events processed in a single flush of the microtask queue? |
@AndreasMadsen or anyone else on @nodejs/async_hooks: Is there a PR or anything to watch (other than this issue) to fix the remaining issues mentioned in #13427 (comment)? |
@Trott No, it is a limitation of PromiseHooks and unfortunately it is not a big priority to fix it :( |
I'm going to close this. PR welcome. Feel free to re-open or comment if you think this should remain open. |
I’m reopening. It is a valid bug, it is just very hard to fix. |
As far as I can tell this is resolved in the latest version of v8.x. Closing. |
Sometimes
async_hooks.currentId()
returns the wrong id. as @AndreasMadsen pointed out hereHere is a simple example that shows this is not always working correctly with promises.
which outputs:
Edited by @ChALkeR: mistype/spelling fix.
The text was updated successfully, but these errors were encountered: