Skip to content

Commit aba0cf3

Browse files
Eugene Ostroukhovtargos
authored andcommitted
inspector: do not change async call stack depth if the worker is done
Fixes: #28528 PR-URL: #28613 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 638c8a3 commit aba0cf3

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎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
voidmaxAsyncCallStackDepthChanged(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+
constcommon=require('../common');
4+
5+
common.skipIfInspectorDisabled();
6+
7+
constassert=require('assert');
8+
const{ Worker }=require('worker_threads');
9+
const{ Session }=require('inspector');
10+
11+
constsession=newSession();
12+
13+
letdone=false;
14+
15+
session.connect();
16+
17+
session.on('NodeWorker.attachedToWorker',({params: { sessionId }})=>{
18+
letid=1;
19+
functionpostToWorkerInspector(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+
functiononMessageReceived({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+
newWorker('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)