You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As (quite complex) work-around we can use web socket connection from main thread and connect to the inspector session. As soon as connection is made, the worker.terminate() activates and code after inspector.waitForDebugger() is not executed.
import{isMainThread,parentPort,Worker}from"node:worker_threads";import{fileURLToPath}from"node:url";importinspectorfrom"node:inspector";importWebSocketfrom"ws";if(isMainThread){constworker=newWorker(fileURLToPath(import.meta.url));consturl=awaitnewPromise((resolve)=>worker.on("message",resolve));consttimeout=setTimeout(async()=>{console.log("Timeout");constws=newWebSocket(url);awaitnewPromise((resolve)=>ws.on("open",resolve));ws.send(JSON.stringify({method: "Runtime.runIfWaitingForDebugger",id: 2}));ws.close();},2_000).unref();awaitworker.terminate();clearTimeout(timeout);console.log("Done");}else{inspector.open();parentPort.postMessage(inspector.url());inspector.waitForDebugger();console.log("Running");// Never executed}
$ node workers.mjs
Debugger listening on ws://127.0.0.1:9229/9fc3b32f-23cf-4597-b79e-30d4a61f32cd
For help, see: https://nodejs.org/en/docs/inspector
Timeout
Debugger attached.
Debugger ending on ws://127.0.0.1:9229/9fc3b32f-23cf-4597-b79e-30d4a61f32cd
For help, see: https://nodejs.org/en/docs/inspector
Done
# process exits correctly
The text was updated successfully, but these errors were encountered:
Version
v20.12.2, v21.7.3
Platform
Darwin Aris-MacBook-Pro.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
worker.terminate()
should terminate the worker and the pendinginspector.waitForDebugger()
process.exit()
should kill the main thread's processCTRL+c
is able to do both requirements.What do you see instead?
Worker does not terminate. Main thread cannot be exited.
Additional information
vitest-dev/vitest#5511
As (quite complex) work-around we can use web socket connection from main thread and connect to the inspector session. As soon as connection is made, the
worker.terminate()
activates and code afterinspector.waitForDebugger()
is not executed.$ node workers.mjs Debugger listening on ws://127.0.0.1:9229/9fc3b32f-23cf-4597-b79e-30d4a61f32cd For help, see: https://nodejs.org/en/docs/inspector Timeout Debugger attached. Debugger ending on ws://127.0.0.1:9229/9fc3b32f-23cf-4597-b79e-30d4a61f32cd For help, see: https://nodejs.org/en/docs/inspector Done # process exits correctly
The text was updated successfully, but these errors were encountered: