timeout presence leads to MiniRacer::ScriptTerminatedError instead of MiniRacer::V8OutOfMemoryError
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, ruby
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- JavaScript
- Star
- 628
- Fork
- 100
- Merge trung bình
- 1 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rubyjs/mini_racer
-
platform: darwin/x86
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
rubyjs/mini_racer#388 · 4 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
rubyjs/mini_racer#376 ·
-
Load script as moduleĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
rubyjs/mini_racer#353 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
rubyjs/mini_racer#346 · 6 bình luận · 1 reaction ·
-
Override `Process._fork`?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rubyjs/mini_racer#324 · 1 bình luận · 1 reaction ·
Tất cả issue của rubyjs/mini_racer
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
AOSSIE-Org/BabyNest#284 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
seek4science/seek#2762 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
feedback simulation workshop
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
githubnext/gh-aw-workshop#5009 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Clinic sharing: fast sync refusal message suggests Delete Data, which only developer builds haveĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
avniproject/avni-client#2228 ·
-
Add: K+ Sport 2 LogoĐang mởcheck:passed logos:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 6 ngày