nodejs / nodejs/node

vm: eval cache mixes up script origins

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

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

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

説明

Bug report

  • Node.js: v24.19.0, v26.8.1, v27.0.0-pre (local build)
  • Platform: Microsoft Windows NT 10.0.26200.0 x64
  • Subsystem: vm
// test.mjs
import assert from 'node:assert/strict';
import { Script } from 'node:vm';

const out = [];

function createScript(name) {
  return new Script(`globalThis.eval('import("node:fs")')`, {
    importModuleDynamically(specifier) {
      out.push(name);
      return import(specifier);
    },
  });
}

const a = createScript('A');
const b = createScript('B');

for (const script of [a, b, a]) {
  await script.runInThisContext();
}

assert.deepEqual(out, ['A', 'B', 'A']);

Running this example as node --experimental-vm-modules test.mjs will give different wrong answers between v24 and v26 because V8 removed delayed caching some time during those releases. However, running with --no-compilation-cache will pass the test assertion.

The bug is with V8. In deps/v8/src/codegen/compiler.cc, around the "cache lookup key" comment, indirect eval uses kNoSourcePosition (-1), and the cache key does not distinguish the originating script. This allows identical eval source text from different scripts in the same realm to produce a false positive cache hit.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された test.mjs を --experimental-vm-modules で実行して問題を再現し、その後、"cache lookup key" コメント付近の deps/v8/src/codegen/compiler.cc を調べます。eval キャッシュの検索と関連するテストを追跡し、スクリプトのオリジンがどのように表現されているかを理解します。コンパイルキャッシュを有効にした状態で A/B/A アサーションが成功し、既存のコンパイルキャッシュなしの動作も正しいままであれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, javascript, node.js
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。