-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |