Skip to content
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 initial implementation #8531

Closed
wants to merge 40 commits into from

Commits on Jan 27, 2017

  1. test: remove async_wrap tests

    The async_wrap API will be changing substantially and breaking the
    existing API. So remove the current tests and add them back after
    they've been reimplemented.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    5d75ba4 View commit details
    Browse the repository at this point in the history
  2. stream_base,tls_wrap: notify on destruct

    Classes like TLSWrap hold a pointer to another StreamBase instance. The
    lifetime of these two are independent and allowed one to be retained
    while the other is cleaned up. In the case of TLSWrap, the private
    member TLSWrap::stream_ would be deleted, while the TLSWrap could still
    attempt to access it to see if it was alive.
    
    Give StreamBase a destruct callback to notify when the class is being
    cleaned up. Use this in TLSWrap to clear out the field.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    53a85f1 View commit details
    Browse the repository at this point in the history
  3. crypto: use named FunctionTemplate

    RandomBytes and PBKDF2 were using the same "generic" ObjectTemplate for
    construction. Instead create one for each that is properly named.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    757ac35 View commit details
    Browse the repository at this point in the history
  4. async_wrap: use more specific providers

    Instead of wrapping several providers into PROVIDER_CRYPTO, have them
    all be named after their class. Rename other providers to also match
    their class names. With the exception of Parser. Which is actually
    HTTPParser.
    
    Add PROVIDER_LENGTH to make better checks in WrapperInfo().
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    29e9d09 View commit details
    Browse the repository at this point in the history
  5. async_wrap: use double, not int64_t, for uid

    The array math in JS converting the in64_t to a safe integer is
    unnecessary. Instead set the field to a double and allow internals
    direct access to the array to reduce overhead. Not ideal, but gets us
    the same number of values and simplifies the JS interface.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    82d8606 View commit details
    Browse the repository at this point in the history
  6. async_wrap: add GetAsyncId() method

    Allow handles to retrieve their own uid's by adding a new method on the
    FunctionTemplates. Implementation of these into all other classes will
    come in a future commit.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    4a427e3 View commit details
    Browse the repository at this point in the history
  7. src: add AsyncWrap::GetAsyncId() to all children

    Add the method AsyncWrap::GetAsyncId() to all inheriting class objects
    so the uid of the handle can be retrieved from JS.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    f5d6056 View commit details
    Browse the repository at this point in the history
  8. async_wrap: only call SetupHooks() once

    The call to async_wrap.setupHooks() will soon become an internal call.
    While other public APIs will be exposed through async_hooks. In
    preparation for this, only allow SetupHooks() to be called once. If
    called again, or if a non-function is passed, throw.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    1c9154c View commit details
    Browse the repository at this point in the history
  9. async_hooks: introduce async_hooks.js

    Getting mechanics flushed out for both the necessary JS and C++ APIs.
    
    Currenty builds and runs, but complete implementation is coming.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    4c809dd View commit details
    Browse the repository at this point in the history
  10. async_hooks: check correct array

    Check the correct array to see if hooks can be executed.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    3611f6a View commit details
    Browse the repository at this point in the history
  11. next_tick: add async_hooks support

    Also did:
    * Turn TickObject() into a function
    * Split the function in half so it can be inlined
    * Fix how uid flags are set
    * Export kScopedTriggerId for use in setupInit()
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    d244d55 View commit details
    Browse the repository at this point in the history
  12. timers: initial timers support

    Also change a couple things to retrieve the initTriggerId the same way
    in all cases.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    977718e View commit details
    Browse the repository at this point in the history
  13. fs: add initial async_hooks support

    The placement of setting/updating the triggerId needs to be tested to
    make sure basic assumptions are met.
    
    Also fix propagation of the triggerId for fs.open(), remove adding
    information to the internal unordered_map for fs.openSync() and return
    the Float64Array to simplify usage.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    3e5ef64 View commit details
    Browse the repository at this point in the history
  14. net: add initial async_hooks net support

    cluster is still slightly messed up, as I figure out how to handle the
    "faux" handles passed to net.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    955d390 View commit details
    Browse the repository at this point in the history
  15. lib: add triggerId support to various modules

    Properly propagate the triggerId in a few more modules.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    da7c67c View commit details
    Browse the repository at this point in the history
  16. http: reset Agents on free pool

    Add function on native side to run AsyncWrap::Reset() from JS. Only add
    this to TCPWrap, since it's the only place necessary.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    b3721ba View commit details
    Browse the repository at this point in the history
  17. src: properly propagate triggerId in more places

    * Setup the currentId and triggerId during bootstrap.
    * Assign _asyncId and _triggerId on construction of Timeout
    * Always run emitBefore/emitAfter in timers to make sure ids are setup
    * Reset ids after after() hooks are called, not before
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    78a2a7f View commit details
    Browse the repository at this point in the history
  18. timers: manually set ids if no hooks exist

    Instead of always calling into emitBefore/emitAfter, set the ids
    manually if there are no hooks to call. Better performance.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    eab9e86 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    4399547 View commit details
    Browse the repository at this point in the history
  20. async_hooks: allow enable/disable while processing

    Safely enable()/disable() hooks while hooks are being processed.
    Otherwise the array length will change and hooks that should/shouldn't
    have been processed will be.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    830428a View commit details
    Browse the repository at this point in the history
  21. async_hooks: run after() in case of exception

    In the case of an exception being caught by _fatalException(), make sure
    to always run the after() callbacks to let the user know the callback
    has completed.
    
    Include test to make sure after() is triggered correctly, including
    having the correct currentId.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    ad382c5 View commit details
    Browse the repository at this point in the history
  22. streams: set initTriggerId before nextTick()

    Properly set the triggerId for the nextTick() call by using the _asyncId
    set on the stream.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    6e5af4a View commit details
    Browse the repository at this point in the history
  23. next_tick: set MicrotaskCallback to the void

    Point the _asyncId and _triggerId of the TickObject used by
    runMicrotasksCallback() to the void. When the PromiseHook API is
    implemented in V8 will address and properly propagate the ids.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    32b5288 View commit details
    Browse the repository at this point in the history
  24. test: allow running with async_hook noops

    Add NODE_TEST_WITH_ASYNC_HOOKS environment variable to allow running
    tests with init/before/after/destroy noops to make sure that basic
    mechanics work properly across all tests.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    bd660a4 View commit details
    Browse the repository at this point in the history
  25. async_hooks: move location of restoreTmpHooks()

    Place restoreTmpHooks() closer to setupTmpActiveHooks() to make it more
    apparent what each is used for.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    e8c27f8 View commit details
    Browse the repository at this point in the history
  26. async_wrap: use v8::Eternal for provider strings

    Switch to using a v8::Eternal array to retrieve the provider strings
    passed as the  "type" to the init() callback.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    0ab9547 View commit details
    Browse the repository at this point in the history
  27. fs: use preallocated Float64Array

    Instead of always passing in a Float64Array to getIdsFromFd()
    preallocate one during initialization and write to those fields
    directly.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    352c89a View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    e9ae576 View commit details
    Browse the repository at this point in the history
  29. async_hooks: verify stack integrity

    When emitAfterS() is called, make sure the id passed in is the same id
    that's on the stack.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    015e665 View commit details
    Browse the repository at this point in the history
  30. async_hooks: place destroy ids on native list

    destroy() hooks from JS should also be called async, but instead of
    trying to do this in a setImmediate, just use the same list that is used
    for native ids.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    e2af82f View commit details
    Browse the repository at this point in the history
  31. test: add more async hook tests

    Add NODE_TEST_HANDLE_ACCESS, which tests if a resource aborts if
    inspected at the end of the process (specifically if the resource has
    been cleaned up on the C++ side), and NODE_CHECK_ASYNC_DESTROY, which
    checks if destroy has been called on the same id twice.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    1b7438f View commit details
    Browse the repository at this point in the history
  32. timers: don't reset _asyncId/_triggerId

    This was originally done as a safety measure, but fails in practice if
    a clear*() is run on the same handle that's currently executing its
    callback.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    ca8d6db View commit details
    Browse the repository at this point in the history
  33. async_hooks: return early if emitting the void

    In some cases, like triggering the microtask queue, there is no id
    (though that should change in the future). So instead trigger that
    execution is happening in the void, and return early if destroy is
    emitted on the void.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    ac2e137 View commit details
    Browse the repository at this point in the history
  34. async_hooks: really always exit on exception

    async_hooks does not allow recovery from errors because it's currently
    unknown what will happen to the state of the application if that
    happens. So instead, force the application to print an error message
    then either exit or abort. Depending on whether the user passed
    --abort-on-uncaught-exception.
    
    exit() is used instead of reallyExit() to allow any 'exit' events to
    fire.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    da138cf View commit details
    Browse the repository at this point in the history
  35. async_wrap: don't allow exports to be overwritten

    ForceSet() everything with v8::ReadOnly | v8::DontDelete to make sure
    none of the object properties can be overridden.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    25dd8af View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    2d98170 View commit details
    Browse the repository at this point in the history
  37. PARTIAL implement new stack tracker

    In order to get a stack tracker that is performant in JS had to do some
    ridiculous stuff. This allows the stack to be tracked from both C++ and
    JS with almost no overhead, and allows it to unwind properly in case
    there's a fatal exception.
    trevnorris committed Jan 27, 2017
    Configuration menu
    Copy the full SHA
    7bc7d3c View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    edf67a7 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    90f0a63 View commit details
    Browse the repository at this point in the history

Commits on Feb 2, 2017

  1. async_wrap: print msg on error instead of abort

    Instead of using a CHECK(), print an error message to the user. Check if
    --abort-on-uncaught-exception has been passed, and abort if this is the
    case. Otherwise exit(1).
    trevnorris committed Feb 2, 2017
    Configuration menu
    Copy the full SHA
    1ff2dfb View commit details
    Browse the repository at this point in the history