summaryrefslogtreecommitdiff
path: root/src/async_wrap.cc
AgeCommit message (Collapse)Author
2018-03-18src: make AsyncWrap constructors delegateDaniel Bevenius
Currently, there is an AsyncWrap constructor that is only used by PromiseWrap. This constructor has a body which is very similar to the other AsyncWrap constructor. This commit suggests updating the private constructor that is used by PromiseWrap and also have the second constructor delegate to this one to avoid the code duplication. PR-URL: https://github.com/nodejs/node/pull/19366 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-03-16src: remove unused uv.h include from async_wrap.ccDaniel Bevenius
PR-URL: https://github.com/nodejs/node/pull/19342 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Khaidi Chu <i@2333.moe>
2018-03-16src: fix indenting of wrap->EmitTraceEventBeforeDaniel Bevenius
PR-URL: https://github.com/nodejs/node/pull/19340 Reviewed-By: James M Snell <jasnell@gmail.com>
2018-03-16src: add extractPromiseWrap functionDaniel Bevenius
Currently PromiseHook extracts the PromiseWrap from a Local<Promise> in two places. This commit extracts that code into a function instead. PR-URL: https://github.com/nodejs/node/pull/19340 Reviewed-By: James M Snell <jasnell@gmail.com>
2018-03-14src: refactor emit before/after/promiseResolveDaniel Bevenius
Currently EmitBefore, EmitAfter, EmitPromiseResolve are very similar. This commit suggests extracting the code they have in common to a new function to reduce code duplication. PR-URL: https://github.com/nodejs/node/pull/19295 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-03-11src: add convenience ctor for async trigger id scopeAnna Henningsen
PR-URL: https://github.com/nodejs/node/pull/19204 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2018-03-09src: add tracing category macrosJames M Snell
Adds `TRACING_CATEGORY_NODE`, `TRACING_CATEGORY_NODE1` and `TRACING_CATEGORY_NODE2` helper macros for consistently building trace event category strings. For instance, `TRACING_CATEGORY_NODE2(foo, bar)` would generate the category string `node,node.foo,node.foo.bar`, such that... ``` TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( TRACING_CATEGORY_NODE2(foo, bar), "baz", 1); ``` Would emit if trace events are enabled for categories: `node`, `node.foo`, or `node.foo.bar`. This allows a natural scoping down of what trace events a user may want to receive. Enabling the `node` category would receive everything Node.js produces. PR-URL: https://github.com/nodejs/node/pull/19155 Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
2018-03-08src: use smart pointer in AsyncWrap::WeakCallbackDaniel Bevenius
PR-URL: https://github.com/nodejs/node/pull/19168 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-22src: fix abort when taking a heap snapshotBen Noordhuis
Remove an erroneous CHECK that asserted the persistent object's internal field pointer still pointed to a valid object. If ClearWrap() has been called, the field pointer equals nullptr and that is expected behavior. PR-URL: https://github.com/nodejs/node/pull/18898 Fixes: https://github.com/nodejs/node/issues/18256 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <matheus@sthima.com>
2018-02-22src: remove unused using declarations async_wrapDaniel Bevenius
PR-URL: https://github.com/nodejs/node/pull/18893 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2018-02-21src: remove unnecessary Reset() callsBen Noordhuis
The previous commit made persistent handles auto-reset on destruction. This commit removes the Reset() calls that are now no longer necessary. PR-URL: https://github.com/nodejs/node/pull/18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-21src: prevent persistent handle resource leaksBen Noordhuis
Replace v8::Persistent with node::Persistent, a specialization that resets the persistent handle on destruction. Prevents accidental resource leaks when forgetting to call .Reset() manually. I'm fairly confident this commit fixes a number of resource leaks that have gone undiagnosed so far. PR-URL: https://github.com/nodejs/node/pull/18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-16async_hooks: clean up usage in internal codeAnatoli Papirovski
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Renames newUid to newAsyncId for added clarity of its purpose. Adjusts usage throughout the codebase, as well as in a couple of tests. PR-URL: https://github.com/nodejs/node/pull/18720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-02-12async_hooks: rename PromiseWrap.parentIdAli Ijaz Sheikh
Rename the `parentId` property on the PromiseWrap object to a `isChainedPromise` property. The former wasn't quite useful as it was always defined to be the same value as the trigger id available in the init hook. Instead rename the property to be closer to the information it communicates: whether the promise is a chained promise or not. PR-URL: https://github.com/nodejs/node/pull/18633 Fixes: https://github.com/nodejs/node/issues/18470 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-02-01async_hooks: clean up commentsAli Ijaz Sheikh
With some of the recent work, some of the comments were no longer representative of the code, or were otherwise unclear. This commit fixes some obvious issues I found. Ref: https://github.com/nodejs/node/commit/83e5215a4e8438a43b9f0002b7a43e2fd2dd37a4 Ref: https://github.com/nodejs/node/commit/0784b0440c05464f79b857f7d8698fcc953d3fb3 PR-URL: https://github.com/nodejs/node/pull/18467 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-01-21async_wrap: schedule destroy hook as unrefAnatoli Papirovski
Since the `DestroyAsyncIdsCallback` in Node.js can be scheduled as a result of GC, that means that it can accidentally keep the event loop open when it shouldn't. Replace `SetImmediate` with the newly introduced `SetUnrefImmediate` and in addition introduce RunBeforeExit callbacks, of which `DestroyAsyncIdsCallback` is now the first. These callbacks will run before the `beforeExit` event is emitted (which will now only be emitted if the event loop is still not active). PR-URL: https://github.com/nodejs/node/pull/18241 Fixes: https://github.com/nodejs/node/issues/18190 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
2018-01-02src: remove duplicate words in commentsTobias Nießen
PR-URL: https://github.com/nodejs/node/pull/17939 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-27async_hooks: use typed array stack as fast pathAnna Henningsen
- Communicate the current async stack length through a typed array field rather than a native binding method - Add a new fixed-size `async_ids_fast_stack` typed array that contains the async ID stack up to a fixed limit. This increases performance noticeably, since most of the time the async ID stack will not be more than a handful of levels deep. - Make the JS `pushAsyncIds()` and `popAsyncIds()` functions do the same thing as the native ones if the fast path is applicable. Benchmarks: $ ./node benchmark/compare.js --new ./node --old ./node-master --runs 10 --filter next-tick process | Rscript benchmark/compare.R [00:03:25|% 100| 6/6 files | 20/20 runs | 1/1 configs]: Done improvement confidence p.value process/next-tick-breadth-args.js millions=4 19.72 % *** 3.013913e-06 process/next-tick-breadth.js millions=4 27.33 % *** 5.847983e-11 process/next-tick-depth-args.js millions=12 40.08 % *** 1.237127e-13 process/next-tick-depth.js millions=12 77.27 % *** 1.413290e-11 process/next-tick-exec-args.js millions=5 13.58 % *** 1.245180e-07 process/next-tick-exec.js millions=5 16.80 % *** 2.961386e-07 PR-URL: https://github.com/nodejs/node/pull/17780 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-24async_hooks: use CHECK instead of throwing errorJon Moss
SetupHooks is only available via `process.binding('async_wrap')`, so there's no reason it shouldn't be called with the appropriate arguments, since it is an internal-only function. The only place this function is used is `lib/internal/async_hooks.js`. PR-URL: https://github.com/nodejs/node/pull/17832 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-12-19async_hooks: use scope for defaultTriggerAsyncIdAndreas Madsen
Previously the getter would mutate the kDefaultTriggerAsncId value. This refactor changes the setter to bind the current kDefaultTriggerAsncId to a scope, such that the getter doesn't have to mutate its own value. PR-URL: https://github.com/nodejs/node/pull/17273 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-19async_hooks: rename initTriggerIdAndreas Madsen
rename initTriggerId to defaultTriggerAsyncId such it matches the rest of our naming. PR-URL: https://github.com/nodejs/node/pull/17273 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-29src: introduce USE() for silencing compiler warningsAnna Henningsen
PR-URL: https://github.com/nodejs/node/pull/17333 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-29src: remove `ClearFatalExceptionHandlers()`Anna Henningsen
At its call sites, `ClearFatalExceptionHandlers()` was used to make the process crash as soon as possible once an exception occurred, without giving JS land a chance to interfere. `ClearFatalExceptionHandlers()` awkwardly removed the current domain and any `uncaughtException` handlers, whereas a clearer way is to execute the relevant reporting (and `exit()`) code directly. PR-URL: https://github.com/nodejs/node/pull/17333 Refs: https://github.com/nodejs/node/pull/17159 Refs: https://github.com/nodejs/node/pull/17324 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-24trace_events: add executionAsyncId to init eventsAndreas Madsen
async_hooks emits trace_events. This adds the executionAsyncId to the init events. In theory this could be inferred from the before and after events but this is much simpler and doesn't require knowledge of all events. PR-URL: https://github.com/nodejs/node/pull/17196 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-21src: remove async_hooks destroy timer handleAnna Henningsen
PR-URL: https://github.com/nodejs/node/pull/17117 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-17src: rename async-wrap -> async_wrapDaniel Bevenius
This commit renames async-wrap to async_wrap for consitency with other c++ source files. PR-URL: https://github.com/nodejs/node/pull/17022 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>