Skip to content

Commit

Permalink
inspector: do not change async call stack depth if the worker is done
Browse files Browse the repository at this point in the history
Fixes: #28528
PR-URL: #28613
Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
eugeneo authored and targos committed Jul 20, 2019
1 parent 638c8a3 commit aba0cf3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-inspector-async-hook-after-done.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit aba0cf3

Please sign in to comment.