Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

timeout presence leads to MiniRacer::ScriptTerminatedError instead of MiniRacer::V8OutOfMemoryError

オープン
#178 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, ruby

調査の方向性

Start with the reproduction in test/mini_racer_test.rb and trace eval timeout handling in lib/mini_racer.rb alongside the MEM_SOFTLIMIT_REACHED and gc_callback code in ext/mini_racer_extension/mini_racer_extension.cc. The issue describes a race that raises the wrong exception; confirm the failure with the provided max_memory and timeout case, then check that memory exhaustion raises MiniRacer::V8OutOfMemoryError.

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

説明

UPD: I can confirm that gc_callback can get executed after rb_context_eval_unsafe was called, but before nogvl_context_eval. MEM_SOFTLIMIT_REACHED is set to false in nogvl_context_eval, but isolate execution would still get terminated, leading to the wrong exception being raised.

It looks like some operations inside of timeout function(https://github.com/rubyjs/mini_racer/blob/master/lib/mini_racer.rb#L328), like Mutex.new are just slow enough to allow for this race condition to happen in the test example.


I've noticed a weird behavior when I set the timeout for the context, it sometimes throws MiniRacer::ScriptTerminatedError exception instead of expected MiniRacer::V8OutOfMemoryError. The script executes fast enough so there shouldn't be the actual timeout error.

Here is an example tests that reproduced the issue:

  # This will pass
  def test_max_memory_2
    context = MiniRacer::Context.new(max_memory: 1_000_000)

    assert_raises(MiniRacer::V8OutOfMemoryError) do
      500.times do |i|
        script = "var t#{i} = '#{SecureRandom.uuid * 1000}'; Array.from(new Array(10000)).map((e, i) => i + 1)[1];"
        context.eval(script)
        sleep 0.001
      end
    end
  end

  # This will fail:
  def test_max_memory_3
    context = MiniRacer::Context.new(max_memory: 1_000_000, timeout: 20_000)

    assert_raises(MiniRacer::V8OutOfMemoryError) do
      500.times do |i|
        script = "var t#{i} = '#{SecureRandom.uuid * 1000}'; Array.from(new Array(10000)).map((e, i) => i + 1)[1];"
        context.eval(script)
        sleep 0.001
      end
    end
  end
.F

Failure:
MiniRacerTest#test_max_memory_3 [.../.../mini_racer/test/mini_racer_test.rb:335]:
[MiniRacer::V8OutOfMemoryError] exception expected, not
Class: <MiniRacer::ScriptTerminatedError>
Message: <"JavaScript was terminated (either by timeout or explicitly)">
---Backtrace---
.../.../mini_racer/lib/mini_racer.rb:209:in `eval_unsafe'
.../.../mini_racer/lib/mini_racer.rb:209:in `block (2 levels) in eval'
.../.../mini_racer/lib/mini_racer.rb:350:in `timeout'
.../.../mini_racer/lib/mini_racer.rb:208:in `block in eval'
.../.../mini_racer/lib/mini_racer.rb:206:in `synchronize'
.../.../mini_racer/lib/mini_racer.rb:206:in `eval'
.../.../mini_racer/test/mini_racer_test.rb:338:in `block (2 levels) in test_max_memory_3'
.../.../mini_racer/test/mini_racer_test.rb:336:in `times'
.../.../mini_racer/test/mini_racer_test.rb:336:in `block in test_max_memory_3'

I suspect that might be some sort of race condition with V8 GC and MEM_SOFTLIMIT_REACHED flag (https://github.com/rubyjs/mini_racer/blob/master/ext/mini_racer_extension/mini_racer_extension.cc#L336, https://github.com/rubyjs/mini_racer/blob/master/ext/mini_racer_extension/mini_racer_extension.cc#L217), but I haven't got a chance to dig into that yet.

ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
VERSION = "0.3.1"
LIBV8_VERSION = "~> 8.4.255"
OSX 
主要言語
JavaScript
スター
628
フォーク
100
平均マージ
1日 20時間
マージ済み PR(30日)
2

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

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

rubyjs/mini_racer のほかの issue

rubyjs/mini_racer の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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