nodejs / nodejs/node

worker_threads that use es modules incorrectly pause when loaded

未关闭
#38,420 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

esm inspector worker
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

  • 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在 VS Code 的 Node.js 调试器下使用 bug/index.js 和 no-bug/index.js 重现该问题。首先比较 ES-module 和 non-module worker 在 inspector.waitForDebugger() 调用以及关联的 VS Code bootloader 附近的行为。完成的标准是:对于 ES-module 情况,调试器不再在 worker 的第一行暂停。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。