-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
process: reduce the number of internal frames in async stack trace #27392
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
Changes from all commits
ef8b228
3def28d
c354c2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 'use strict'; | ||
|
|
||
| async function one() { | ||
| throw new Error('test'); | ||
| } | ||
|
|
||
| async function breaker() { | ||
| return true; | ||
| } | ||
|
|
||
| async function stack() { | ||
| await breaker(); | ||
| } | ||
|
|
||
| async function two() { | ||
| await stack(); | ||
| await one(); | ||
| } | ||
| async function three() { | ||
| await two(); | ||
| } | ||
|
|
||
| async function four() { | ||
| await three(); | ||
| } | ||
|
|
||
| module.exports = four; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const four = require('../common/fixtures') | ||
| .readSync('async-error.js') | ||
| .toString() | ||
| .split('\n') | ||
| .slice(2, -2) | ||
| .join('\n'); | ||
|
|
||
| const main = `${four} | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
| `; | ||
|
|
||
| // --eval CJS | ||
| { | ||
| const child = spawnSync(process.execPath, [ | ||
| '-e', | ||
| main | ||
| ], { | ||
| env: { ...process.env } | ||
| }); | ||
|
|
||
| if (child.status !== 0) { | ||
| console.error(child.stderr.toString()); | ||
| } | ||
| console.error(child.stdout.toString()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Error: test | ||
| at one ([eval]:2:9) | ||
| at two ([eval]:15:9) | ||
| at async three ([eval]:18:3) | ||
| at async four ([eval]:22:3) | ||
| at async main ([eval]:28:5) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const four = require('../common/fixtures') | ||
| .readSync('async-error.js') | ||
| .toString() | ||
| .split('\n') | ||
| .slice(2, -2) | ||
| .join('\n'); | ||
|
|
||
| const main = `${four} | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
| `; | ||
|
|
||
| // --eval ESM | ||
| { | ||
| const child = spawnSync(process.execPath, [ | ||
| '--experimental-modules', | ||
| '--input-type', | ||
| 'module', | ||
| '-e', | ||
| main | ||
| ], { | ||
| env: { ...process.env } | ||
| }); | ||
|
|
||
| if (child.status !== 0) { | ||
| console.error(child.stderr.toString()); | ||
| } | ||
| console.error(child.stdout.toString()); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Error: test | ||
| at one (eval:1:2:9) | ||
| at two (eval:1:15:9) | ||
| at processTicksAndRejections (internal/process/task_queues.js:*:*) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't totally eliminate this yet because the tick callback is, in the end, implemented in JavaScript to reduce the overhead of calling into JS. (This patch only moves the initial one-off invocation of the tick callback to C++, all subsequent invocations of the tick callback already come from C++, usually through To hide this eventually we may need an API from V8 to mark the call site as internal. But it is at least better than |
||
| at async three (eval:1:18:3) | ||
| at async four (eval:1:22:3) | ||
| at async main (eval:1:28:5) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const four = require('../fixtures/async-error'); | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
|
|
||
| queueMicrotask(main); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Error: test | ||
| at one (*fixtures*async-error.js:4:9) | ||
| at two (*fixtures*async-error.js:17:9) | ||
| at async three (*fixtures*async-error.js:20:3) | ||
| at async four (*fixtures*async-error.js:24:3) | ||
| at async main (*message*async_error_microtask_main.js:7:5) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was previously: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const four = require('../fixtures/async-error'); | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
|
|
||
| process.nextTick(main); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Error: test | ||
| at one (*fixtures*async-error.js:4:9) | ||
| at two (*fixtures*async-error.js:17:9) | ||
| at processTicksAndRejections (internal/process/task_queues.js:*:*) | ||
| at async three (*fixtures*async-error.js:20:3) | ||
| at async four (*fixtures*async-error.js:24:3) | ||
| at async main (*message*async_error_nexttick_main.js:7:5) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Flags: --experimental-modules | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import four from '../fixtures/async-error.js'; | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| (node:*) ExperimentalWarning: The ESM module loader is experimental. | ||
| Error: test | ||
| at one (*fixtures*async-error.js:4:9) | ||
| at two (*fixtures*async-error.js:17:9) | ||
| at async three (*fixtures*async-error.js:20:3) | ||
| at async four (*fixtures*async-error.js:24:3) | ||
| at async main (*message*async_error_sync_esm.mjs:8:5) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const four = require('../fixtures/async-error'); | ||
|
|
||
| async function main() { | ||
| try { | ||
| await four(); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Error: test | ||
| at one (*fixtures*async-error.js:4:9) | ||
| at two (*fixtures*async-error.js:17:9) | ||
| at async three (*fixtures*async-error.js:20:3) | ||
| at async four (*fixtures*async-error.js:24:3) | ||
| at async main (*message*async_error_sync_main.js:7:5) |
Uh oh!
There was an error while loading. Please reload this page.