Skip to content

Commit 94e0488

Browse files
addaleaxMylesBorins
authored andcommitted
inspector: no async tracking for promises
`Promise` instances are already tracked by V8 itself. This fixes `sequential/test-inspector-async-stack-traces-promise-then` in debug mode (it previously crashed because our tracking and the V8 tracking were not properly nested). PR-URL: #17118 Refs: https://chromium-review.googlesource.com/c/v8/v8/+/707058 Fixes: #17017 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5247ab3 commit 94e0488

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/internal/inspector_async_hook.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,33 @@ const hook = createHook({
1616
// in https://github.com/nodejs/node/pull/13870#discussion_r124515293,
1717
// this should be fine as long as we call asyncTaskCanceled() too.
1818
const recurring = true;
19-
inspector.asyncTaskScheduled(type, asyncId, recurring);
19+
if (type === 'PROMISE')
20+
this.promiseIds.add(asyncId);
21+
else
22+
inspector.asyncTaskScheduled(type, asyncId, recurring);
2023
},
2124

2225
before(asyncId) {
26+
if (this.promiseIds.has(asyncId))
27+
return;
2328
inspector.asyncTaskStarted(asyncId);
2429
},
2530

2631
after(asyncId) {
32+
if (this.promiseIds.has(asyncId))
33+
return;
2734
inspector.asyncTaskFinished(asyncId);
2835
},
2936

3037
destroy(asyncId) {
38+
if (this.promiseIds.has(asyncId))
39+
return this.promiseIds.delete(asyncId);
3140
inspector.asyncTaskCanceled(asyncId);
3241
},
3342
});
3443

44+
hook.promiseIds = new Set();
45+
3546
function enable() {
3647
if (config.bits < 64) {
3748
// V8 Inspector stores task ids as (void*) pointers.

test/sequential/test-inspector-async-stack-traces-promise-then.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function debuggerPausedAt(msg, functionName, previousTickLocation) {
5454
`${Object.keys(msg.params)} contains "asyncStackTrace" property`);
5555

5656
assert.strictEqual(msg.params.callFrames[0].functionName, functionName);
57-
assert.strictEqual(msg.params.asyncStackTrace.description, 'PROMISE');
57+
assert.strictEqual(msg.params.asyncStackTrace.description, 'Promise.resolve');
5858

5959
const frameLocations = msg.params.asyncStackTrace.callFrames.map(
6060
(frame) => `${frame.functionName}:${frame.lineNumber}`);

0 commit comments

Comments
 (0)