Skip to content

parentIds in NextTickWrap? #7

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

Closed
Jeff-Lewis opened this issue Jul 2, 2016 · 1 comment
Closed

parentIds in NextTickWrap? #7

Jeff-Lewis opened this issue Jul 2, 2016 · 1 comment

Comments

@Jeff-Lewis
Copy link

Jeff-Lewis commented Jul 2, 2016

Hi, I'm experimenting with creating a version of CLS that uses async-hook and AsyncWrap instead of the older AsyncListener and it appears that it very rarely sees parentIds in the init hook.

Is this b/c of NextTickerWrap doesn't pass them? Is there an alternate way to wrap nextTick to include it?

@AndreasMadsen
Copy link
Owner

The parentId for NextTickerWrap is supposed to be null. In the final version of AsyncWrap that will also be the case.

This is because parentId is only set when a handle was directly created as a result of a another handle. Most popular example is a TCP server (parent) creating a TCP socket (child). The much more normal case is that some JavaScript code invoked for example nextTick and that way created a handle object. In this case the handle was created from a callback execution and not another handle.

The standard pattern for tracking the parent is:

  • track the handle id (currentId) for the currently executing callback using the pre and post hooks.
  • In the init hook use parent = parentId === null ? currentId : parentId.

example: https://github.com/AndreasMadsen/trace/blob/master/trace.js#L49
documentation: https://github.com/nodejs/diagnostics/tree/master/tracing/AsyncWrap#parentuid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants