nodejs / nodejs/node

Scripts are sent in a non-existent `executionContextId`

未关闭
#47,438 13 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Version

19.8.1

Platform

Darwin MacBook-Pro-2.guest.corp.microsoft.com 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64

Subsystem

inspector

What steps will reproduce the bug?

Run the following script:

const { Session } = require('node:inspector');

const session = new Session();
const executionContexts = new Map();
session.on('Runtime.executionContextCreated', call => {
  console.log(call);
  executionContexts.set(call.params.context.id, call.params.context);
});
session.on('Debugger.scriptParsed', call => {
  console.log(call);
  if (!executionContexts.has(call.params.executionContextId)) {
    console.error(`Got script in execution context ${call.params.executionContextId}, but have only ${[...executionContexts.keys()].join()}`);
    process.exit(1);
  }
});

session.connect();

session.post('Runtime.enable', () => {
  console.log('Runtime enabled')

  session.post('Debugger.enable', () => {
    console.log('Debugger enabled')
  });
});
How often does it reproduce? Is there a required condition?

100% of the time

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

The script should run successfully. All execution contexts should come in Runtime.executionContextCreated events before Runtime.enable returns.

What do you see instead?
{
  method: 'Runtime.executionContextCreated',
  params: {
    context: {
      id: 1,
      origin: '',
      name: '/Users/connor/.asdf/installs/nodejs/19.8.1/bin/node[90017]',
      uniqueId: '-8333824095165494686.-3638729329792817601',
      auxData: [Object]
    }
  }
}
Runtime enabled
{
  method: 'Debugger.scriptParsed',
  params: {
    scriptId: '6',
    url: 'node:internal/per_context/primordials',
    startLine: 0,
    startColumn: 0,
    endLine: 737,
    endColumn: 0,
    executionContextId: 0,
    hash: 'bc07b5754e60d05f0e36aee626f46b4561cc1d342c7c84e1655eca736753f7f8',
    isLiveEdit: false,
    sourceMapURL: '',
    hasSourceURL: false,
    isModule: false,
    length: 21457,
    stackTrace: { callFrames: [Array] },
    scriptLanguage: 'JavaScript',
    embedderName: 'node:internal/per_context/primordials'
  }
}
Got script in execution context 0, but have only 1
Additional information

Later scripts are in the execution context ID of 1, but earlier ones are in the non-existent 0 context.

Originally came up in vscode-js-debug as a result of adding more intended correctness around how execution contexts are handled https://github.com/microsoft/vscode-js-debug/issues/1643

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 node:inspector 的 Session 入口点开始,运行复现脚本以观察 Runtime.executionContextCreated 和 Debugger.scriptParsed 的顺序。跟踪 Runtime.enable 和 Debugger.enable 涉及的 inspector 事件处理;当报告的脚本事件使用现有的执行上下文,且复现过程完成而不退出时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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