| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d85a05 commit fd318e7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,12 +18,14 @@ The available categories are: | |||
| 18 | 18 | The [`async_hooks`] events have a unique `asyncId` and a special `triggerId` | |
| 19 | 19 | `triggerAsyncId` property. | |
| 20 | 20 | * `node.bootstrap` - Enables capture of Node.js bootstrap milestones. | |
| 21 | + * `node.fs.sync` - Enables capture of trace data for file system sync methods. | ||
| 21 | 22 | * `node.perf` - Enables capture of [Performance API] measurements. | |
| 22 | 23 | * `node.perf.usertiming` - Enables capture of only Performance API User Timing | |
| 23 | 24 | measures and marks. | |
| 24 | 25 | * `node.perf.timerify` - Enables capture of only Performance API timerify | |
| 25 | 26 | measurements. | |
| 26 | - * `node.fs.sync` - Enables capture of trace data for file system sync methods. | ||
| 27 | + * `node.promises.rejections` - Enables capture of trace data tracking the number | ||
| 28 | + of unhandled Promise rejections and handled-after-rejections. | ||
| 27 | 29 | * `node.vm.script` - Enables capture of trace data for the `vm` module's | |
| 28 | 30 | `runInNewContext()`, `runInContext()`, and `runInThisContext()` methods. | |
| 29 | 31 | * `v8` - The [V8] events are GC, compiling, and execution related. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,8 @@ | |||
| 3 | 3 | #include "node_internals.h" | |
| 4 | 4 | #include "v8.h" | |
| 5 | 5 | ||
| 6 | + #include <atomic> | ||
| 7 | + | ||
| 6 | 8 | namespace node { | |
| 7 | 9 | ||
| 8 | 10 | using v8::Array; | |
@@ -51,6 +53,9 @@ void SetupNextTick(const FunctionCallbackInfo<Value>& args) { | |||
| 51 | 53 | } | |
| 52 | 54 | ||
| 53 | 55 | void PromiseRejectCallback(PromiseRejectMessage message) { | |
| 56 | + static std::atomic<uint64_t> unhandledRejections{0}; | ||
| 57 | + static std::atomic<uint64_t> rejectionsHandledAfter{0}; | ||
| 58 | + | ||
| 54 | 59 | Local<Promise> promise = message.GetPromise(); | |
| 55 | 60 | Isolate* isolate = promise->GetIsolate(); | |
| 56 | 61 | PromiseRejectEvent event = message.GetEvent(); | |
@@ -65,13 +70,23 @@ void PromiseRejectCallback(PromiseRejectMessage message) { | |||
| 65 | 70 | ||
| 66 | 71 | if (value.IsEmpty()) | |
| 67 | 72 | value = Undefined(isolate); | |
| 73 | + | ||
| 74 | + unhandledRejections++; | ||
| 68 | 75 | } else if (event == v8::kPromiseHandlerAddedAfterReject) { | |
| 69 | 76 | callback = env->promise_reject_handled_function(); | |
| 70 | 77 | value = Undefined(isolate); | |
| 78 | + | ||
| 79 | + rejectionsHandledAfter++; | ||
| 71 | 80 | } else { | |
| 72 | 81 | return; | |
| 73 | 82 | } | |
| 74 | 83 | ||
| 84 | + TRACE_COUNTER2(TRACING_CATEGORY_NODE2(promises, rejections), | ||
| 85 | + "rejections", | ||
| 86 | + "unhandled", unhandledRejections, | ||
| 87 | + "handledAfter", rejectionsHandledAfter); | ||
| 88 | + | ||
| 89 | + | ||
| 75 | 90 | Local<Value> args[] = { promise, value }; | |
| 76 | 91 | MaybeLocal<Value> ret = callback->Call(env->context(), | |
| 77 | 92 | Undefined(isolate), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cp = require('child_process'); | ||
| 5 | + const path = require('path'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + const tmpdir = require('../common/tmpdir'); | ||
| 8 | + | ||
| 9 | + common.disableCrashOnUnhandledRejection(); | ||
| 10 | + | ||
| 11 | + if (!common.isMainThread) | ||
| 12 | + common.skip('process.chdir is not available in Workers'); | ||
| 13 | + | ||
| 14 | + if (process.argv[2] === 'child') { | ||
| 15 | + const p = Promise.reject(1); // Handled later | ||
| 16 | + Promise.reject(2); // Unhandled | ||
| 17 | + setImmediate(() => { | ||
| 18 | + p.catch(() => { /* intentional noop */ }); | ||
| 19 | + }); | ||
| 20 | + } else { | ||
| 21 | + tmpdir.refresh(); | ||
| 22 | + process.chdir(tmpdir.path); | ||
| 23 | + | ||
| 24 | + const proc = cp.fork(__filename, | ||
| 25 | + [ 'child' ], { | ||
| 26 | + execArgv: [ | ||
| 27 | + '--no-warnings', | ||
| 28 | + '--trace-event-categories', | ||
| 29 | + 'node.promises.rejections' | ||
| 30 | + ] | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + proc.once('exit', common.mustCall(() => { | ||
| 34 | + const file = path.join(tmpdir.path, 'node_trace.1.log'); | ||
| 35 | + | ||
| 36 | + assert(common.fileExists(file)); | ||
| 37 | + fs.readFile(file, common.mustCall((err, data) => { | ||
| 38 | + const traces = JSON.parse(data.toString()).traceEvents | ||
| 39 | + .filter((trace) => trace.cat !== '__metadata'); | ||
| 40 | + traces.forEach((trace) => { | ||
| 41 | + assert.strictEqual(trace.pid, proc.pid); | ||
| 42 | + assert.strictEqual(trace.name, 'rejections'); | ||
| 43 | + assert(trace.args.unhandled <= 2); | ||
| 44 | + assert(trace.args.handledAfter <= 1); | ||
| 45 | + }); | ||
| 46 | + })); | ||
| 47 | + })); | ||
| 48 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments