Commit 50f84564 authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[inspector] Reset the async task stack when resetting the context group

This CL fixes an issue with async stacks. The async task stack is not
torn down between page navigations or reloads. The result is that
any new async tasks are stacked on top of the old pages async task
stack.

This was not prominent until now for two reasons:
  1) Async tasks created in blink are always finished as long as
     destructors have time to run.
  2) When V8 is terminated while running the micro task queue also
     all async tasks created for Promises (including `await`) are
     cleaned up properly.

Introducing the stack tagging API made it more common for having
unfinished async tasks open outside the MTQ, which left the
async task stack non-empty during navigation.

This CL fixes this problem by clearing out all the async task
and async stack data structures for a context group when that
context group is reset.

R=bmeurer@chromium.org, victorporof@chromium.org

Fixed: chromium:1328785
Change-Id: Iee0c3c4a55f66e643829dae3726dc03c735da1dd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3666620Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80741}
parent 702f0ff1
......@@ -1963,6 +1963,7 @@ void V8DebuggerAgentImpl::reset() {
m_scripts.clear();
m_cachedScripts.clear();
m_cachedScriptSize = 0;
m_debugger->allAsyncTasksCanceled();
}
void V8DebuggerAgentImpl::ScriptCollected(const V8DebuggerScript* script) {
......
Clear the async stack on navigations
---------- console.trace: 0 ----------
bar (test.js:7:10)
(anonymous) (test.js:12:0)
-- foo --
foo (test.js:2:17)
(anonymous) (test.js:12:4)
---------- console.trace: 1 ----------
bar (test.js:7:10)
(anonymous) (test.js:12:0)
-- foo --
foo (test.js:2:17)
(anonymous) (test.js:12:4)
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --experimental-async-stack-tagging-api
const {session, contextGroup, Protocol} = InspectorTest.start('Clear the async stack on navigations');
const script = `
function foo() {
return console.scheduleAsyncTask("foo", true);
}
function bar(id) {
console.startAsyncTask(id);
console.trace(id); // When context is reset, this trace gets broken.
// no finish
console.cancelAsyncTask(id);
}
bar(foo());
`;
session.setupScriptMap();
(async () => {
Protocol.Runtime.onConsoleAPICalled(({params}) => {
InspectorTest.log(`---------- console.${params.type}: ${params.args[0].value} ----------`);
session.logCallFrames(params.stackTrace.callFrames);
session.logAsyncStackTrace(params.stackTrace.parent);
});
await Protocol.Runtime.enable();
await Protocol.Debugger.enable();
await Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });
contextGroup.addScript(script, 0, 0, 'test.js');
await Protocol.Debugger.onceScriptParsed();
contextGroup.reset();
// Run the same script again and make sure that the task stack has been reset.
contextGroup.addScript(script, 0, 0, 'test.js');
await Protocol.Debugger.onceScriptParsed();
InspectorTest.completeTest();
})();
......@@ -217,6 +217,7 @@
'regress/regress-crbug-1197392': [SKIP],
'debugger/command-line-api-with-arrow-function': [SKIP],
'regress/regress-crbug-1199919': [SKIP],
'console/clear-async-stack-on-context-reset': [SKIP],
'console/destroy-context-during-log': [SKIP],
'console/scoped-variables': [SKIP],
'cpu-profiler/console-profile': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment