AndreasMadsen / async-hook

Inspect the life of handle objects in node
MIT License
36 stars 14 forks source link

parentIds in NextTickWrap? #7

Closed Jeff-Lewis closed 8 years ago

Jeff-Lewis commented 8 years ago

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 commented 8 years ago

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:

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