-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trace_events: add node.promises category, rejection counter
Allow the trace event log to include a count of unhandled rejections and handled after rejections. This is useful primarily as a quick check to see if rejections may be going unhandled (and unnoticed in a process). PR-URL: #22124 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
common.disableCrashOnUnhandledRejection(); | ||
|
||
if (!common.isMainThread) | ||
common.skip('process.chdir is not available in Workers'); | ||
|
||
if (process.argv[2] === 'child') { | ||
const p = Promise.reject(1); // Handled later | ||
Promise.reject(2); // Unhandled | ||
setImmediate(() => { | ||
p.catch(() => { /* intentional noop */ }); | ||
}); | ||
} else { | ||
tmpdir.refresh(); | ||
process.chdir(tmpdir.path); | ||
|
||
const proc = cp.fork(__filename, | ||
[ 'child' ], { | ||
execArgv: [ | ||
'--no-warnings', | ||
'--trace-event-categories', | ||
'node.promises.rejections' | ||
] | ||
}); | ||
|
||
proc.once('exit', common.mustCall(() => { | ||
const file = path.join(tmpdir.path, 'node_trace.1.log'); | ||
|
||
assert(common.fileExists(file)); | ||
fs.readFile(file, common.mustCall((err, data) => { | ||
const traces = JSON.parse(data.toString()).traceEvents | ||
.filter((trace) => trace.cat !== '__metadata'); | ||
traces.forEach((trace) => { | ||
assert.strictEqual(trace.pid, proc.pid); | ||
assert.strictEqual(trace.name, 'rejections'); | ||
assert(trace.args.unhandled <= 2); | ||
assert(trace.args.handledAfter <= 1); | ||
}); | ||
})); | ||
})); | ||
} |