-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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() don't return the expected value in context of the connection callback of net.Server #21078
Comments
ping @nodejs/async_hooks — not sure what the correct outcome here is. I can see validity to both, depending on how one thinks about it. Either way, seems like the documentation doesn't match the reality so one of the two needs to be updated. |
This has broken cls-hooked since 8.10.0. It's been raised as an issue in Just to confirm what @tingshao stated above, when I compare logs of 8.9.4 (left) to 8.10.0 (right), the change from |
@nodejs/async_hooks @AndreasMadsen @addaleax What are your thoughts on this? It appears the documentation doesn't match the behavior or are we missing something? If so, do we have more options than this?
Thank you! |
@AndreasMadsen @addaleax Looks like this was never addressed. I assume at this point it's too late to expect behaviour change, so probably simple documentation change would suffice? |
@kibertoad Well, basically what @apapirovski said … I can see the validity of either point of view. I think what this issue is waiting for is for somebody to have a strong enough opinion to either change the docs or change the behavior here, but yeah, a documentation change would definitely suffice. |
async_hooks.triggerAsyncId() is expected to return the async id of the connection in the
onconnection
callback of server. This was specifically declared in the example of the async_hooks documentation which can be found here.However, after testing the example using both node 10.3.0 and 8.11.2, I found the result was different. Below is the code and output of my test.
my code:
if I connect the server with another terminal by
connect localhost 8000
, then the output is:Please note the line
-- conn callback, triggerAsyncId: 1, executionAsyncId: 5
. It means in the connection callback, the triggerAsyncId is 1 instead of 7 which is expected.I investigated the code, and found the root cause is:
When the callback is made, it was made on the TCPWrap instance of the server, and the server's triggerId (1) and asyncId (5) were pushed into the stack, thus lead to this result. While It seems that this mechanism is ok most of the time for normal callbacks, but for this new connection callback, I think we should add some logic to pass the triggerId of the new connection (actually a new TCPWrap instance) to push into the stack. I made a change based on that and verified the result, it could work.
So, I doubt is the issue due to document obsoleted or the code should be changed?
I'd like to make a PR if it is confirmed, thanks.
The text was updated successfully, but these errors were encountered: