node icon indicating copy to clipboard operation
node copied to clipboard

`worker_threads` stuck when passed `execArgv: ["--inspect-brk"]`

Open AriPerkkio opened this issue 8 months ago • 0 comments

Version

v20.15.0

Platform

Darwin Aris-MacBook-Air.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

// worker-repro.mjs
import { isMainThread, Worker } from "node:worker_threads";
import { fileURLToPath } from "node:url";

if (isMainThread) {
  const worker = new Worker(fileURLToPath(import.meta.url), {
    execArgv: ["--inspect-brk"],
  });
  await new Promise((r) => setTimeout(r, 1_000));

  setTimeout(() => {
    console.log("Time out waiting for terminate, calling process.exit()");
    process.exit();
  }, 1000).unref();

  setTimeout(
    () => console.log("This is never logged but process.exit doesnt exit"),
    2000
  ).unref();

  console.log("Terminating...");
  await worker.terminate();
  console.log("Done");
} else {
  console.log("Worker running");
}

How often does it reproduce? Is there a required condition?

Always on 20.15.0. Works fine on 20.14.0.

What is the expected behavior? Why is that the expected behavior?

  • Worker should start
  • Worker should exit
  • Main thread should exit
ari ~/Git/repros  $ nvm use 20.14.0
Now using node v20.14.0 (npm v10.7.0)
ari ~/Git/repros  $ node worker-repro.mjs 
Worker running
Terminating...
Done

What do you see instead?

  • Worker does not start
  • worker.terminate() is stuck
  • process.exit() does not exit the main process
ari ~/Git/repros  $ node worker-repro.mjs 
Terminating...
Time out waiting for terminate, calling process.exit()
# Stuck here forever, exits on CTRL+c

Additional information

Even though --inspect-brk doesn't work on workers (https://github.com/nodejs/node/issues/26609#issuecomment-1463605558), it still shouldn't make them stuck.

AriPerkkio avatar Jun 30 '24 06:06 AriPerkkio