nodejs / nodejs/node

Scripts are sent in a non-existent `executionContextId`

オープン
#47,438 コメント 13 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

c++ inspector stale
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。