timeout presence leads to MiniRacer::ScriptTerminatedError instead of MiniRacer::V8OutOfMemoryError
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 38/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- javascript, ruby
- 領域
- backend, performance
研究方向
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 小時
- 30 天內合併 PR
- 2
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rubyjs/mini_racer 的其他 Issue
-
bug/crash platform: linux/x86
難度 4/5 3-5 天 新手友好度 42/100
rubyjs/mini_racer#422 · 10 則留言 ·
-
platform: darwin/x86
難度 4/5 3-5 天 新手友好度 35/100
rubyjs/mini_racer#388 · 4 則留言 ·
-
難度 5/5 一週以上 新手友好度 20/100
rubyjs/mini_racer#376 ·
-
難度 4/5 3-5 天 新手友好度 45/100
rubyjs/mini_racer#353 ·
-
難度 3/5 1-2 天 新手友好度 35/100
rubyjs/mini_racer#346 · 6 則留言 · 1 個 reaction ·
查看 rubyjs/mini_racer 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
維護者通常 1 天內回覆
-
Cloudredirect未關閉
難度 1/5 1 小時以內 新手友好度 70/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
NanmiCoder/dsh-agent-teams#277 ·
維護者通常 1 天內回覆
-
[ordering-review] workshop order graph: 1 confirmed ordering problem, 3 cycles are false positives未關閉
難度 2/5 1-3 小時 新手友好度 78/100
githubnext/gh-aw-workshop#4943 ·
維護者通常 1 天內回覆