inspector: do not change async call stack depth if the worker is done
Fixes: https://github.com/nodejs/node/issues/28528 PR-URL: https://github.com/nodejs/node/pull/28613 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
440a344f68
commit
7e543bb2e4
@ -483,6 +483,11 @@ class NodeInspectorClient : public V8InspectorClient {
|
||||
}
|
||||
|
||||
void maxAsyncCallStackDepthChanged(int depth) override {
|
||||
if (waiting_for_sessions_disconnect_) {
|
||||
// V8 isolate is mostly done and is only letting Inspector protocol
|
||||
// clients gather data.
|
||||
return;
|
||||
}
|
||||
if (auto agent = env_->inspector_agent()) {
|
||||
if (depth == 0) {
|
||||
agent->DisableAsyncHook();
|
||||
|
60
test/parallel/test-inspector-async-hook-after-done.js
Normal file
60
test/parallel/test-inspector-async-hook-after-done.js
Normal file
@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const { Worker } = require('worker_threads');
|
||||
const { Session } = require('inspector');
|
||||
|
||||
const session = new Session();
|
||||
|
||||
let done = false;
|
||||
|
||||
session.connect();
|
||||
|
||||
session.on('NodeWorker.attachedToWorker', ({ params: { sessionId } }) => {
|
||||
let id = 1;
|
||||
function postToWorkerInspector(method, params) {
|
||||
session.post('NodeWorker.sendMessageToWorker', {
|
||||
sessionId,
|
||||
message: JSON.stringify({ id: id++, method, params })
|
||||
}, () => console.log(`Message ${method} received the response`));
|
||||
}
|
||||
|
||||
// Wait for the notification
|
||||
function onMessageReceived({ params: { message } }) {
|
||||
if (!message ||
|
||||
JSON.parse(message).method !== 'NodeRuntime.waitingForDisconnect') {
|
||||
session.once('NodeWorker.receivedMessageFromWorker', onMessageReceived);
|
||||
return;
|
||||
}
|
||||
// Force a call to node::inspector::Agent::ToggleAsyncHook by changing the
|
||||
// async call stack depth
|
||||
postToWorkerInspector('Debugger.setAsyncCallStackDepth', { maxDepth: 1 });
|
||||
// This is were the original crash happened
|
||||
session.post('NodeWorker.detach', { sessionId }, () => {
|
||||
done = true;
|
||||
});
|
||||
}
|
||||
|
||||
onMessageReceived({ params: { message: null } });
|
||||
// Enable the debugger, otherwise setAsyncCallStackDepth does nothing
|
||||
postToWorkerInspector('Debugger.enable');
|
||||
// Start waiting for disconnect notification
|
||||
postToWorkerInspector('NodeRuntime.notifyWhenWaitingForDisconnect',
|
||||
{ enabled: true });
|
||||
// start worker
|
||||
postToWorkerInspector('Runtime.runIfWaitingForDebugger');
|
||||
});
|
||||
|
||||
session.post('NodeWorker.enable', { waitForDebuggerOnStart: true }, () => {
|
||||
new Worker('console.log("Worker is done")', { eval: true })
|
||||
.once('exit', () => {
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(done, true);
|
||||
console.log('Test is done');
|
||||
}, 0);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user