Skip to content

Commit aba0cf3

Browse files
eugeneotargos
authored andcommitted
inspector: do not change async call stack depth if the worker is done
Fixes: #28528 PR-URL: #28613 Reviewed-By: Aleksei Koziatinskii <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 638c8a3 commit aba0cf3

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/inspector_agent.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ class NodeInspectorClient : public V8InspectorClient {
483483
}
484484

485485
void maxAsyncCallStackDepthChanged(int depth) override {
486+
if (waiting_for_sessions_disconnect_) {
487+
// V8 isolate is mostly done and is only letting Inspector protocol
488+
// clients gather data.
489+
return;
490+
}
486491
if (auto agent = env_->inspector_agent()) {
487492
if (depth == 0) {
488493
agent->DisableAsyncHook();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
common.skipIfInspectorDisabled();
6+
7+
const assert = require('assert');
8+
const { Worker } = require('worker_threads');
9+
const { Session } = require('inspector');
10+
11+
const session = new Session();
12+
13+
let done = false;
14+
15+
session.connect();
16+
17+
session.on('NodeWorker.attachedToWorker', ({ params: { sessionId } }) => {
18+
let id = 1;
19+
function postToWorkerInspector(method, params) {
20+
session.post('NodeWorker.sendMessageToWorker', {
21+
sessionId,
22+
message: JSON.stringify({ id: id++, method, params })
23+
}, () => console.log(`Message ${method} received the response`));
24+
}
25+
26+
// Wait for the notification
27+
function onMessageReceived({ params: { message } }) {
28+
if (!message ||
29+
JSON.parse(message).method !== 'NodeRuntime.waitingForDisconnect') {
30+
session.once('NodeWorker.receivedMessageFromWorker', onMessageReceived);
31+
return;
32+
}
33+
// Force a call to node::inspector::Agent::ToggleAsyncHook by changing the
34+
// async call stack depth
35+
postToWorkerInspector('Debugger.setAsyncCallStackDepth', { maxDepth: 1 });
36+
// This is were the original crash happened
37+
session.post('NodeWorker.detach', { sessionId }, () => {
38+
done = true;
39+
});
40+
}
41+
42+
onMessageReceived({ params: { message: null } });
43+
// Enable the debugger, otherwise setAsyncCallStackDepth does nothing
44+
postToWorkerInspector('Debugger.enable');
45+
// Start waiting for disconnect notification
46+
postToWorkerInspector('NodeRuntime.notifyWhenWaitingForDisconnect',
47+
{ enabled: true });
48+
// start worker
49+
postToWorkerInspector('Runtime.runIfWaitingForDebugger');
50+
});
51+
52+
session.post('NodeWorker.enable', { waitForDebuggerOnStart: true }, () => {
53+
new Worker('console.log("Worker is done")', { eval: true })
54+
.once('exit', () => {
55+
setTimeout(() => {
56+
assert.strictEqual(done, true);
57+
console.log('Test is done');
58+
}, 0);
59+
});
60+
});

0 commit comments

Comments
 (0)