Skip to content

mini_racer 0.12.0 Segmentation fault on x86_64-linux with libv8-node 21.7.2.0 #300

Closed

Description

@D-system

Hello the team

Thank you for the update to libv8-node 21.7.2.0 yesterday.
I wanted to report an error.
Setup:

  • mini_racer 0.12.0
  • libv8-node 21.7.2.0
  • ruby 3.2.3
  • OS: Ubuntu 22.04.3 LTS (from CircleCI cimg/ruby:3.2.3-node)
  • Rails: 6.1.7.7
  • Sprockets: 4.2.1
  • The command: RAILS_ENV=production SECRET_KEY_BASE=1 bin/rails assets:clobber assets:precompile
/home/circleci/ec/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:228: [BUG] Segmentation fault at 0x00007f3f10a31008
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0048 p:---- s:0301 e:000300 CFUNC  :eval_unsafe
c:0047 p:0009 s:0295 e:000294 BLOCK  /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:228
c:0046 p:0010 s:0292 e:000291 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:348
c:0045 p:0008 s:0281 e:000280 BLOCK  /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:227 [FINISH]
c:0044 p:---- s:0278 e:000277 CFUNC  :synchronize
c:0043 p:0045 s:0274 e:000273 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:225
c:0042 p:0007 s:0267 e:000266 BLOCK  /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:11
c:0041 p:0003 s:0264 e:000262 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:67
c:0040 p:0035 s:0256 e:000255 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:10 [FINISH]
c:0039 p:---- s:0249 e:000248 CFUNC  :new
c:0038 p:0038 s:0242 e:000241 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/runtime.rb:68
c:0037 p:0013 s:0236 e:000235 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/module.rb:27
c:0036 p:0020 s:0230 e:000229 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:189
c:0035 p:0065 s:0223 e:000221 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:229
SEGV received in SEGV handler
c:0034 p:0014 s:0212 e:000211 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:181
c:0033 p:0029 s:0206 e:000205 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser/compressor.rb:36
c:0032 p:0007 s:0198 e:000197 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser/compressor.rb:23
c:0031 p:0047 s:0193 e:000192 METHOD /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84
c:0030 p:0013 s:0185 e:000184 BLOCK  /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66 [FINISH]
c:0029 p:---- s:0180 e:000179 CFUNC  :reverse_each
c:0028 p:0035 
Received "aborted" signal

It does work on Darwin Kernel Version 23.2.0 arm64 (Mac on arm) that compile from source.

The error is from eval -> eval_unsafe, so I suspect it is an issue with the libv8-node

eval_unsafe(str, filename)

Activity

  1. tisba commented on Apr 23, 2024

    @tisba
    Collaborator

    Hey @D-system. A couple of question hopefully helping to narrow the issue down

    • Can you reproduce it with a freshly created rails application? On aarch64-linux my basic checks works, as well as rails new foo && cd foo && bundle install && RAILS_ENV=production SECRET_KEY_BASE=1 bin/rails assets:clobber assets:precompile using cimg/ruby:3.2.3-node.

    • Can you reproduce the issue with Ruby 3.3.0?

    • Can you confirm if you're using jemalloc or not? Looks like the image is at least installing libjemalloc, I haven't checked if they build Ruby against it, or using LD_PRELOAD, or using this up to the user. There have been various issues with jemalloc and mini_racer/v8. In case jemalloc is used, can you try without?

  2. D-system commented on Apr 23, 2024

    @D-system
    Author

    I don't think jemalloc is enabled:

    $ ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
    -lz -lrt -lrt -ldl -lcrypt -lm -lpthread

    Even by using the LD_PRELOAD, it does not seems to work:

    $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2  ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
    -lz -lrt -lrt -ldl -lcrypt -lm -lpthread
    
    
    # Checking the directory
    $ ls -l /usr/lib/x86_64-linux-gnu/libjemalloc*
    -rw-r--r-- 1 root root 1119814 Jan 24  2022 /usr/lib/x86_64-linux-gnu/libjemalloc.a
    -rw-r--r-- 1 root root 1119970 Jan 24  2022 /usr/lib/x86_64-linux-gnu/libjemalloc_pic.a
    lrwxrwxrwx 1 root root      16 Jan 24  2022 /usr/lib/x86_64-linux-gnu/libjemalloc.so -> libjemalloc.so.2
    -rw-r--r-- 1 root root  744440 Jan 24  2022 /usr/lib/x86_64-linux-gnu/libjemalloc.so.2

    Let me see if I can make a new app and get the same error.


    I didn't realized there was a more debug output:

    Details ```

    -- Ruby level backtrace information ----------------------------------------
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in block in create_worker' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in catch'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in block (2 levels) in create_worker' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in loop'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in block (3 levels) in create_worker' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in run_task'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promise.rb:564:in block in realize' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in execute'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in synchronize' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in synchronize'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in block in synchronize' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in block in execute'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in block (2 levels) in find' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in to_a'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in each' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:88:in find_all_linked_assets'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:81:in find_asset' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in load'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:206:in fetch_or_store' /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:187:in fetch'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:207:in block in fetch_or_store' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in block in load'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:43:in load' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:339:in fetch_asset_from_dependency_cache'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:59:in block in load' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:184:in load_from_unloaded'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in call_processors' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in reverse_each'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66:in block in call_processors' /home/circleci/repo/vendor/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84:in call_processor'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser/compressor.rb:23:in call' /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser/compressor.rb:36:in call'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:181:in compile_with_map' /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:229:in run_terserjs'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/terser-1.2.2/lib/terser.rb:189:in context' /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/module.rb:27:in compile'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/runtime.rb:68:in compile' /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/runtime.rb:68:in new'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:10:in initialize' /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:67:in translate'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/mini_racer_runtime.rb:11:in block in initialize' /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:225:in eval'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:225:in synchronize' /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:227:in block in eval'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:348:in timeout' /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:228:in block (2 levels) in eval'
    /home/circleci/repo/vendor/ruby/3.2.0/gems/mini_racer-0.12.0/lib/mini_racer.rb:228:in `eval_unsafe'

    -- Machine register context ------------------------------------------------
    RIP: 0x00007f97ea8d24e7 RBP: 0x00007f977fefa220 RSP: 0x00007f977fefa1e0
    RAX: 0x00007f97edbd1000 RBX: 0x00007f96ec003000 RCX: 0x0000000000001000
    RDX: 0x0000000000002127 RDI: 0x00007f96ec003000 RSI: 0x000000000003c000
    R8: 0x0000000000040000 R9: 0x00007f977831dd10 R10: 0x00007f977831fc20
    R11: 0x8bdbe29ebe0b09bc R12: 0x0000000000002000 R13: 0x00007f97edbb8000
    R14: 0x000000000003c000 R15: 0x00005597131dd5a0 EFL: 0x0000000000010202

    -- C level backtrace information -------------------------------------------
    SEGV received in SEGV handler

    </details>
    
  3. D-system commented on Apr 23, 2024

    @D-system
    Author

    I made a brand new Rails 6.1.7.7 app I got the same error with those changes:

    • remove webpacker
    • add gem "bootstrap", "~> 4.3"
    • add gem "sprockets-rails" (it does error out with sprockets and without webpacker)
    • add gem "mini_racer", "~> 0.12.0"

    Note: it does precompile the files then seg fault.

    Details ``` $ bundle ; ./bin/rails assets:clobber assets:precompile Bundle complete! 18 Gemfile dependencies, 84 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. I, [2024-04-23T18:59:24.147478 #10018] INFO -- : Removed /home/circleci/new_rails_app/public/assets yarn install v1.22.19 [1/4] Resolving packages... success Already up-to-date. Done in 0.42s. I, [2024-04-23T18:59:25.739888 #10018] INFO -- : Writing /home/circleci/new_rails_app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js I, [2024-04-23T18:59:25.740896 #10018] INFO -- : Writing /home/circleci/new_rails_app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js.gz I, [2024-04-23T18:59:25.741133 #10018] INFO -- : Writing /home/circleci/new_rails_app/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css I, [2024-04-23T18:59:25.742186 #10018] INFO -- : Writing /home/circleci/new_rails_app/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz ./bin/rails: [BUG] Segmentation fault at 0x00007fb3f7901008 ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux]

    -- Control frame information -----------------------------------------------
    c:0001 p:0000 s:0003 E:0011f0 DUMMY [FINISH]

    -- Machine register context ------------------------------------------------
    RIP: 0x00007fb3f4602745 RBP: 0x00007ffea2fe8d10 RSP: 0x00007ffea2fe8c80
    RAX: 0x00007fb3f7901000 RBX: 0x00007fb374bc0000 RCX: 0x000000000003cfff
    RDX: 0x000000000003bfff RDI: 0x00007fb374bc3000 RSI: 0x000000000003c000
    R8: 0x00007fb3ec07e680 R9: 0x0000000000000000 R10: 0x00007fb3fe254f70
    R11: 0x69454a582143dfed R12: 0x00007fb3ec03dd08 R13: 0x00007fb374bc3000
    R14: 0x0000555dc5c6e350 R15: 0x000000000003c000 EFL: 0x0000000000010202

    -- C level backtrace information -------------------------------------------
    /usr/local/lib/libruby.so.3.2(rb_print_backtrace+0xd) [0x7fb3fe90494f] /home/circleci/ruby/vm_dump.c:785
    /usr/local/lib/libruby.so.3.2(rb_vm_bugreport) /home/circleci/ruby/vm_dump.c:1080
    /usr/local/lib/libruby.so.3.2(rb_bug_for_fatal_signal+0xf4) [0x7fb3fe6fb664] /home/circleci/ruby/error.c:813
    /usr/local/lib/libruby.so.3.2(sigsegv+0x4d) [0x7fb3fe853f5d] /home/circleci/ruby/signal.c:964
    /lib/x86_64-linux-gnu/libc.so.6(0x7fb3fe285520) [0x7fb3fe285520]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4602745) [0x7fb3f4602745]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4e18bbd) [0x7fb3f4e18bbd]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4e18c16) [0x7fb3f4e18c16]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4e60288) [0x7fb3f4e60288]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4e08210) [0x7fb3f4e08210]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4e07ffe) [0x7fb3f4e07ffe]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f4dffe15) [0x7fb3f4dffe15]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f491cba1) [0x7fb3f491cba1]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f491c619) [0x7fb3f491c619]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f44abaa0) [0x7fb3f44abaa0]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(0x7fb3f44ae2c2) [0x7fb3f44ae2c2]
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(free_context_raw+0x137) [0x7fb3f44abc4f] /home/circleci/.rubygems/gems/mini_racer-0.12.0/ext/mini_racer_extension/mini_racer_extension.cc:1461
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(free_context+0xec) [0x7fb3f44abde5] /home/circleci/.rubygems/gems/mini_racer-0.12.0/ext/mini_racer_extension/mini_racer_extension.cc:1489
    /home/circleci/.rubygems/extensions/x86_64-linux/3.2.0/mini_racer-0.12.0/mini_racer_extension.so(deallocate+0x24) [0x7fb3f44abea0] /home/circleci/.rubygems/gems/mini_racer-0.12.0/ext/mini_racer_extension/mini_racer_extension.cc:1516
    /usr/local/lib/libruby.so.3.2(run_final+0xf) [0x7fb3fe71dea2] /home/circleci/ruby/gc.c:4399
    /usr/local/lib/libruby.so.3.2(finalize_list) /home/circleci/ruby/gc.c:4418
    /usr/local/lib/libruby.so.3.2(finalize_deferred_heap_pages) /home/circleci/ruby/gc.c:4447
    /usr/local/lib/libruby.so.3.2(rb_objspace_call_finalizer+0x350) [0x7fb3fe72a4c0] /home/circleci/ruby/gc.c:4584
    /usr/local/lib/libruby.so.3.2(rb_ec_finalize+0x2a) [0x7fb3fe706c31] /home/circleci/ruby/eval.c:168
    /usr/local/lib/libruby.so.3.2(rb_ec_cleanup) /home/circleci/ruby/eval.c:262
    /usr/local/lib/libruby.so.3.2(ruby_run_node+0x9d) [0x7fb3fe706e7d] /home/circleci/ruby/eval.c:330
    /usr/local/bin/ruby(rb_main+0x21) [0x555dc3f48187] ./main.c:38
    /usr/local/bin/ruby(main) ./main.c:57
    /lib/x86_64-linux-gnu/libc.so.6(0x7fb3fe26cd90) [0x7fb3fe26cd90]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7fb3fe26ce40]
    [0x555dc3f481d5]

    -- Other runtime information -----------------------------------------------

    • Loaded script: ./bin/rails

    • Loaded features:

      0 enumerator.so
      1 thread.rb
      2 fiber.so
      3 rational.so
      4 complex.so
      5 ruby2_keywords.rb
      6 /usr/local/lib/ruby/3.2.0/x86_64-linux/enc/encdb.so
      7 /usr/local/lib/ruby/3.2.0/x86_64-linux/enc/trans/transdb.so
      8 /usr/local/lib/ruby/3.2.0/x86_64-linux/rbconfig.rb
      9 /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/compatibility.rb
      10 /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/defaults.rb
      11 /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/deprecate.rb
      12 /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/errors.rb
      13 /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/unknown_command_spell_checker.rb

    [...]

    
    </details>
    
  4. D-system commented on Apr 23, 2024

    @D-system
    Author

    I also tried the same project with mini_racer 0.9. It works.

    $ bundle ; ./bin/rails assets:clobber assets:precompile
    Fetching gem metadata from https://rubygems.org/..........
    Resolving dependencies...
    Fetching libv8-node 18.19.0.0 (x86_64-linux) (was 21.7.2.0)
    Installing libv8-node 18.19.0.0 (x86_64-linux) (was 21.7.2.0)
    Fetching mini_racer 0.9.0 (was 0.12.0)
    Installing mini_racer 0.9.0 (was 0.12.0) with native extensions
    Bundle complete! 18 Gemfile dependencies, 84 gems now installed.
    Use `bundle info [gemname]` to see where a bundled gem is installed.
    I, [2024-04-23T19:04:10.030111 #10198]  INFO -- : Removed /home/circleci/new_rails_app/public/assets
    yarn install v1.22.19
    [1/4] Resolving packages...
    success Already up-to-date.
    Done in 0.37s.
    I, [2024-04-23T19:04:11.476483 #10198]  INFO -- : Writing /home/circleci/new_rails_app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js
    I, [2024-04-23T19:04:11.477493 #10198]  INFO -- : Writing /home/circleci/new_rails_app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js.gz
    I, [2024-04-23T19:04:11.477738 #10198]  INFO -- : Writing /home/circleci/new_rails_app/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css
    I, [2024-04-23T19:04:11.478602 #10198]  INFO -- : Writing /home/circleci/new_rails_app/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz
    $
    
  5. D-system commented on Apr 23, 2024

    @D-system
    Author

    It seems sprocket is used by default if no other assets pipeline exists.

    The Gemfile without the comments

    source 'https://rubygems.org'
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }
    
    ruby '3.2.3'
    
    gem 'rails', '~> 6.1.7', '>= 6.1.7.7'
    gem 'sqlite3', '~> 1.4'
    gem 'puma', '~> 5.0'
    gem 'sass-rails', '>= 6'
    gem 'turbolinks', '~> 5'
    gem 'jbuilder', '~> 2.7'
    
    gem "bootstrap", "~> 4.3"    # <- the problem
    gem "mini_racer", "~> 0.9.0" # <- added
    
    gem 'bootsnap', '>= 1.4.4', require: false
    
    group :development, :test do
      gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
    end
    
    group :development do
      gem 'web-console', '>= 4.1.0'
      gem 'rack-mini-profiler', '~> 2.0'
      gem 'listen', '~> 3.3'
      gem 'spring'
    end
    
    group :test do
      gem 'capybara', '>= 3.26'
      gem 'selenium-webdriver', '>= 4.0.0.rc1'
      gem 'webdrivers'
    end
    
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
  6. SamSaffron commented on Apr 23, 2024

    @SamSaffron
    Collaborator

    @lloeki this looks urgent , should we roll out a release that puts us back at an earlier version while we work this out ?

  7. SamSaffron commented on Apr 23, 2024

    @SamSaffron
    Collaborator

    @D-system does this repro in Linux as well

  8. D-system commented on Apr 23, 2024

    @D-system
    Author

    @SamSaffron it's all tested inside the CircleCI image linked above. So, it's an Ubuntu based linux on x86_64.

  9. lloeki commented on Apr 23, 2024

    @lloeki
    Collaborator

    should we roll out a release that puts us back at an earlier version while we work this out ?

    So the idea would be to have 0.12.1 be 0.9.0? That would be odd.

  10. lloeki commented on Apr 23, 2024

    @lloeki
    Collaborator

    I'll try a repro.

  11. D-system commented on Apr 23, 2024

    @D-system
    Author

    The official ruby:3.2.3 Docker image does not have that problem.
    Trying with cimg/ruby:3.2.3-node on my local machine (instead of their data centers)

  12. tisba commented on Apr 23, 2024

    @tisba
    Collaborator

    I'm not able to reproduce yet, can't spend much time on it right now though.

    The product I'm working on in my day job is using docker images based on the ruby:3.3.0 and we have an extensive test suite with lots of JavaScript that is evaluated by mini_racer. It works with 0.12.0 on x86 and aarch64 (both linux) just fine, I also have no issues on macOS 14.4.1 (arm). Running directly on x86 without Docker in Github Actions is also fine.

    🤔

  13. D-system commented on Apr 23, 2024

    @D-system
    Author

    I tried with cimg/ruby:3.2.3-node as base image with --platform=x86_64, I was not able to reproduce the problem.
    eg: FROM --platform=x86_64 cimg/ruby:3.2.3-node

    I'm not able to reproduce the issue in a local docker either.

  14. lloeki commented on Apr 23, 2024

    @lloeki
    Collaborator

    LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"

    LD_PRELOAD wouldn't change RbConfig::CONFIG['MAINLIBS'] output, it'd just forcefully inject jemalloc symbols into it.

    In any case it appears that RbConfig::CONFIG['MAINLIBS'] doesn't contain anything about jemalloc anyway, even when statically built against jemalloc.

    I'm not able to reproduce the issue in a local docker either.

    I couldn't reproduce it either inside that x86_64 image: test suite passes, even when artificially stressing libv8 by throwing copious amounts of quickly hacked JS code processing to it (granted it was a real quick test).

  15. added a commit that references this issue on Apr 23, 2024
  16. 86 remaining items

  17. lloeki commented on Aug 6, 2024

    @lloeki
    Collaborator

    Thanks folks for the unrelenting work in trying to reproduce! ❤️

    mini_racer no longer support any Ruby earlier than ruby 3.1. who knows maybe there are multiple issues here...

    By and large this doesn't matter, we could be building libv8 on a Rubyless image for all it cares. I plan to actually do that and move to something that makes having reproducible builds with better libc coverage (something like manylinux or even Nix).

    Where I am super stuck now is figuring out how to get symbols going all the way through so I can get at least a full backtrace from v8 to have some clue of where v8 is crashing.

    • In libexec/build_libv8 the BUILDTYPE env var defaults to Release, IIRC it can be set to Debug instead: env BUILDTYPE=Debug ./libexec/build-libv8.
    • There's a strip step in libexec/inject-libv8 because even in Release mode the obj files resulting from build-libv8 are insanely huge (as in, gigabytes, and IIRC even more so in Debug). Instead of stripping via inject-libv8, one would instead simply manually copy (or symlink to save space) src/libv8-{version}/..../out/{Debug or Release}/libv8_monolith.a to vendor/v8/{platform}/libv8/obj.

    Super sorry I cannot help as it absolutely refuses to crash on any of my machines, whatever I throw at it :(

    By the way the latest linux-gnu builds have been done with GCC.

    Somewhere between 18.13 and 18.19 we broke test/test_forking.rb, it used to work fine, now it segfaults.

    Huh, I didn't see that one, been running tests locally before pushing and they all passed (except the "libv8 now optimises the hell out of things" ones which are red herrings)

    I released 0.14 which now reverts the v8 upgrades. I really want to be on latest v8 but we can not yet, we need a stable release out there and that trumps wanting an upgrade

    At least this way:

    • the default is known stable
    • people have the option not use a more recent release if it happens to work for their use case
  18. lloeki commented on Aug 6, 2024

    @lloeki
    Collaborator

    Note: rr has the ability to record execution and allows replaying execution even on totally foreign machines. Once someone gets debug symbols and records a crash, maybe that could help for me to get a hand on a replayable record.

  19. SamSaffron commented on Aug 7, 2024

    @SamSaffron
    Collaborator

    @lloeki do you get segfaults on local from test_forking?

    Still struggling through this, I know how amazing it will be to have a nice standalone test that segfaults, it is just very hard to pin down.

  20. SamSaffron commented on Aug 8, 2024

    @SamSaffron
    Collaborator

    Well, I just built 12.7.224.15 from Source using the Google build toolchain.

    Had to make some minor change to mini_racer:

    --- a/ext/mini_racer_extension/mini_racer_extension.cc
    +++ b/ext/mini_racer_extension/mini_racer_extension.cc
    @@ -518,7 +518,7 @@ nogvl_context_eval(void* arg) {
         MaybeLocal<Script> parsed_script;
     
         if (eval_params->filename) {
    -        origin = new v8::ScriptOrigin(isolate, *eval_params->filename);
    +        origin = new v8::ScriptOrigin(*eval_params->filename);
         }
     
         parsed_script = Script::Compile(context, *eval_params->eval, origin);
    @@ -791,7 +791,7 @@ static bool run_extra_code(Isolate *isolate, Local<v8::Context> context,
         }
         Local<String> resource_name =
                 String::NewFromUtf8(isolate, name).ToLocalChecked();
    -    ScriptOrigin origin(isolate, resource_name);
    +    ScriptOrigin origin(resource_name);
         ScriptCompiler::Source source(source_string, origin);
         Local<Script> script;
         if (!ScriptCompiler::Compile(context, &source).ToLocal(&script))
    @@ -954,9 +954,12 @@ static VALUE rb_isolate_idle_notification(VALUE self, VALUE idle_time_in_ms) {
     
         if (current_platform == NULL) return Qfalse;
     
    -    double duration = NUM2DBL(idle_time_in_ms) / 1000.0;
    -    double now = current_platform->MonotonicallyIncreasingTime();
    -    return isolate_info->isolate->IdleNotificationDeadline(now + duration) ? Qtrue : Qfalse;
    +    //double duration = NUM2DBL(idle_time_in_ms) / 1000.0;
    +    //double now = current_platform->MonotonicallyIncreasingTime();
    +    //return isolate_info->isolate->IdleNotificationDeadline(now + duration) ? Qtrue : Qfalse;
    +
    +    isolate_info->isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate);
    +    return Qtrue;
     }
    
    

    And now the test that was crashing with the forking is working perfectly.

    I enabled pointer compression and c++20 which is now required.

    I am not sure I am trusting this node build anymore for our purpose. Will see if I can double test this on build as well. I had some trouble building though cause finding the right toolchain for older builds is a bit more tricky... will see what I can do.

    We need to get test/test_forking.rb working as a #1 priority. This appears to be the canary in the coalmine.

  21. SamSaffron commented on Aug 8, 2024

    @SamSaffron
    Collaborator

    @lloeki my branch here builds v8 from source

    mini_racer/Rakefile

    Lines 31 to 39 in f134478

    desc "build libv8 dependencies using Docker"
    task :build_libv8 do
    Dir.chdir("docker") do
    system "docker buildx build . -t mini_racer_lib_v8"
    system "rm -rf ../vendor"
    system "mkdir -p ../vendor"
    system "docker run --rm --user $(id -u):$(id -g) -v $(pwd)/../vendor:/vendor mini_racer_lib_v8 cp -r /package/v8 /vendor"
    end
    end

    This build works just fine both with localization AND with the test_forking that was failing before.

    So I suspect something about the way this node build is working is ending up with a corrupt ICU setup which is leading to the various faults.

  22. SamSaffron commented on Aug 8, 2024

    @SamSaffron
    Collaborator

    OK another repro of the crash is a blank install of Discourse then:

    (0..2).map {  Thread.new { PrettyText.cook("hello") }  } 
    

    something about multithreading is causing segfaults and this is also happening on my builds

  23. SamSaffron commented on Sep 5, 2024

    @SamSaffron
    Collaborator

    This is resolved, we disabled memory protection keys in v8

    Underlying issue is tracked at:

    https://issues.chromium.org/issues/360909072

    New version of mini_racer is now based on latest version of v8 that is shipped with node.js

  24. tisba commented on Sep 5, 2024

    @tisba
    Collaborator

    That's great to hear! The build on aarch alpine is broken and mini_racer won't compile there, but that's probably unrelated. Will investigate a little and open a new issue.

  25. SamSaffron commented on Sep 5, 2024

    @SamSaffron
    Collaborator

    We are now seeing different and new issues:

    #0  0x00007f9eda540e2c in __pthread_kill_implementation (threadid=1227, signo=24957, signo@entry=11, no_tid=11, no_tid@entry=0) at ./nptl/pthread_kill.c:43
    #1  0x00007f9eda540e9f in __pthread_kill_internal (signo=11, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
    #2  0x00007f9eda4f1fb2 in __GI_raise (sig=sig@entry=11) at ../sysdeps/posix/raise.c:26
    #3  0x00007f9edaa3ffaf in ruby_default_signal (sig=sig@entry=11) at signal.c:422
    #4  0x00007f9eda82c3a9 in rb_bug_for_fatal_signal (default_sighandler=0x0, sig=sig@entry=11, ctx=ctx@entry=0x7f9ea30d1ac0, fmt=fmt@entry=0x7f9edac514d5 "Segmentation fault at %p") at error.c:1069
    #5  0x00007f9edaa3ef3b in sigsegv (sig=11, info=0x7f9ea30d1bf0, ctx=0x7f9ea30d1ac0) at signal.c:926
    #6  <signal handler called>
    #7  0x00007f9eb5346e63 in v8::internal::WriteBarrier::MarkingSlow(v8::internal::Tagged<v8::internal::HeapObject>, v8::internal::FullHeapObjectSlot, v8::internal::Tagged<v8::internal::HeapObject>) ()
       from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #8  0x00007f9eb55874c2 in v8::internal::Compiler::DisposeTurbofanCompilationJob(v8::internal::Isolate*, v8::internal::TurbofanCompilationJob*, bool) ()
       from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #9  0x00007f9eb5d49740 in v8::internal::OptimizingCompileDispatcher::FlushOutputQueue(bool) () from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #10 0x00007f9eb5d49a53 in v8::internal::OptimizingCompileDispatcher::Flush(v8::internal::BlockingBehavior) ()
       from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #11 0x00007f9eb548239e in v8::internal::Isolate::AbortConcurrentOptimization(v8::internal::BlockingBehavior) ()
       from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #12 0x00007f9eb5400de8 in v8::internal::Heap::CollectAllAvailableGarbage(v8::internal::GarbageCollectionReason) ()
       from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #13 0x00007f9eb52b8914 in v8::Isolate::LowMemoryNotification() () from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mini_racer-0.15.0/lib/mini_racer_extension.so
    #14 0x00007f9eb5282601 in rb_isolate_low_memory_notification (self=140319468385640) at mini_racer_extension.cc:970
    #15 0x00007f9edaac52fc in vm_call_cfunc_with_frame_ (stack_bottom=<optimized out>, argv=<optimized out>, argc=0, calling=<optimized out>, reg_cfp=0x7f9e7d590eb0, ec=0x7f9e9c48ebd0)
        at /tmp/ruby-build.20240822030420.245.5BFPlP/ruby-3.3.3/vm_insnhelper.c:3490
    
    

    It is going to take us a bit longer to get this v8 upgrade completed

  26. D-system commented on Sep 6, 2024

    @D-system
    Author

    Sorry for the extreme late reply.
    I tried 0.17.0.pre with my project and it works.
    Note that Rails went up to v7.0.8.4.

    Interesting to see the Chromium issue ticket mentioning this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/crash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions