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

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 https://github.com/rubyjs/mini_racer/blob/5b2a25cdb4c84c7500ed47639ef8c664f5bac26d/lib/mini_racer.rb#L228

About this issue

  • Original URL
  • State: open
  • Created 2 months ago
  • Comments: 27

Commits related to this issue

Most upvoted comments

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).

I’m still not able to reproduce it in a local Docker even when I use the Docker image of the CI.

I continue to investigate on the CI directly. SSH and vi for the win!

Anyway, I track down the issue. On a brand new Rails 6.1 app:

  • precompile assets: no problem
  • add mini_racer: no problem
  • add bootstrap 4: problem (let’s look at bootstrap own dependencies)
  • removed bootstrap and added sassc-rails: no problem
  • removed sassc-rails and added autoprefixer-rails 10.4.16.0: problem
  • removed autoprefixer-rails and added execjs 2.9.1: no problem

autoprefixer-rails has only execjs as dependency. In my very case, autoprefixer-rails might have some code that seg fault in the CI only.

I don’t know what else I could search.

I am indeed using puma in clustered mode, but it was working fine on 0.8.0, and starting puma in single mode gives me the same segfault in the same place. I have the suggested fork safety line in an initializer, and removing this makes no difference in any scenario.

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?