-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pressing Ctrl+C
when --inspector-brk
is used but debugger is not connected hangs Vitest
#5511
Comments
This is what's happening when import { isMainThread, Worker } from "node:worker_threads";
import { fileURLToPath } from "node:url";
import inspector from "node:inspector";
const filename = fileURLToPath(import.meta.url);
if (isMainThread) {
const worker = new Worker(filename);
await new Promise((r) => setTimeout(r, 1_000));
console.log("Terminating...");
const timeout = setTimeout(() => console.log("Stuck here"), 2_000);
await worker.terminate();
clearTimeout(timeout);
console.log("Done");
} else {
inspector.open();
inspector.waitForDebugger();
}
The
|
Maybe we can send the event |
For that I think we would need to connect to the Worker's inspector session from main thread with web socket. There's also For the inspector session's web socket connection we have similar setups here: vitest/test/inspect/test/inspect.test.ts Lines 13 to 16 in 6157282
Worker not terminating when it's paused in |
Can't we send |
Inside the Worker But connecting to the inspector session and sending vitest/test/inspect/test/inspect.test.ts Lines 22 to 25 in 6157282
|
This would work: import { isMainThread, parentPort, Worker } from "node:worker_threads";
import { fileURLToPath } from "node:url";
import inspector from "node:inspector";
import WebSocket from "ws";
const filename = fileURLToPath(import.meta.url);
if (isMainThread) {
const worker = new Worker(filename);
const url = await new Promise((resolve) => worker.on("message", resolve));
const timeout = setTimeout(async () => {
console.log("Timeout");
const ws = new WebSocket(url);
await new Promise((resolve) => ws.on("open", resolve));
ws.send(JSON.stringify({ method: "Runtime.runIfWaitingForDebugger", id: 2 }));
ws.close();
}, 2_000).unref();
await worker.terminate();
clearTimeout(timeout);
console.log("Done");
} else {
inspector.open();
parentPort.postMessage(inspector.url());
inspector.waitForDebugger();
console.log("Running"); // Never logged
} |
This should be fixed in Node v22.2.0: nodejs/node#52971 $ node -v
v22.2.0
$ node worker-repro.mjs
Debugger listening on ws://127.0.0.1:9229/2b239484-37a6-4a4d-ba9d-099db758906d
For help, see: https://nodejs.org/en/docs/inspector
Terminating...
Done |
Describe the bug
When trying to debug Vitest with a break, Vitest hangs indefinitely if no connection is ever established.
Reproduction
https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: