nodejs / nodejs/node

worker_threads that use es modules incorrectly pause when loaded

Open
#38,420 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

esm inspector worker
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

  • Version: 16.0.0
  • Platform: Win 10 x64
  • Subsystem: inspector
What steps will reproduce the bug?

It's easiest to run under a debugger that supports worker threads, like VS Code's Node.js debugger. I've created an example repo here:

  1. Open the folder in VS Code
  2. In the debug view (play button on the left hand side), select "No Bug" and hit the play button. This runs no-bug/index.js.
  3. A worker thread spawns, logs its message, and exits
  4. Now select "Bug", and hit the play button. This runs bug/index.js: the same code in an ES module.
  5. The debugger pauses on the first line in the worker
How often does it reproduce? Is there a required condition?

100%

What is the expected behavior?

The debugger doesn't pause with ES modules

What do you see instead?

The debugger pauses

Additional information

It looks like Node.js is incorrectly reporting that the program is started with inspectBrk:

VS Code (and Webstorm I think, though I haven't tried to repro there) use a bootloader to inject ourselves into the process via NODE_OPTIONS. We don't actually invoke with --inspect-brk, we manually call inspector.waitForDebugger(). I'm guessing this triggers inspectBrk to be true, but I haven't debugged into it that far.

This was originally reported in https://github.com/microsoft/vscode/issues/122170

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with bug/index.js and no-bug/index.js under VS Code’s Node.js debugger. Start by comparing the ES-module and non-module worker behavior around the inspector.waitForDebugger() call and the linked VS Code bootloader. Done means the debugger no longer pauses on the worker’s first line for the ES-module case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.