Closed envygeeks closed 9 months ago
@envygeeks Thanks for submitting this bug. We're currently working on the next version of the ruby racer that should address instability issues such as this. If you could outline the steps you took to generate this error, I'd be eager to include it into the regression suite in order to make sure that it does not happen again.
gem install therubyracer -- --use--system-libraries
You might want to pre-install libv8 with a source version (as you already know) because alpine has no glibc, then you can install Discourse and it will trigger the bug 100% of the time with rake assets:precompile
.
Gonna CC @SamSaffron and @eviltrout ... even though they don't support Alpine Linux as a Docker image (or any Docker image that is not their own) they can provide inside into what their code is doing so I can build a re-production script without the need to install full Discourse to trigger it.
As a sidenote @cowboyd I would love to try the new version if it's available.
It can be found here https://github.com/cowboyd/therubyracer/pull/348
It should be noted that large portions of the API remain either omitted or broken. That said, it can do basic javascript evaluation.
Here is the parts of the test suite that are currently passing https://github.com/cowboyd/therubyracer/blob/upgrade-to-v8-4.5/spec/v8/context_spec.rb
Also having trouble on Alpine Linux. I get a load error because of missing symbol:
/srv/service/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require': Error relocating /srv/service/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/therubyracer-0.12.1/v8/init.so: __vfprintf_chk: symbol not found - /srv/service/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/therubyracer-0.12.1/v8/init.so (LoadError)
from /srv/service/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
from /srv/service/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
from /srv/service/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
from /srv/service/vendor/bundle/ruby/2.1.0/gems/therubyracer-0.12.1/lib/v8.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
...
@johnae, can you check if rubygems
installed a binary version of libv8 on your system? (Paste the output of gem list libv8
)
@cowboyd, does rubygems
even acknowledge the existence of different implementations of libc?
@ignisf possibly it did:
bundle exec gem list libv8
*** LOCAL GEMS ***
libv8 (3.16.14.7 x86_64-linux)
I tried doing this:
bundle config build.therubyracer --use-system-libraries
bundle config build.libv8 --with-system-v8
Didn't seem to have any effect.
As far as I see, Alpine provides v8 3.26. I am almost certain that they changed v8's API several times between 3.16 and 3.26 :(. therubyracer
is most probably incompatible with it. You could try explicitly setting a source version of libv8 in your Gemfile
and try again. See https://github.com/cowboyd/libv8#source-and-binary-releases
(also, remove the use system libraries switch from the bundle config beforehand)
You need to use --use-system-libraries
and skip the --with-system-v8
The whole point of skipping the latter is to get therubyracer to compile it's bundled v8 with musl.
@envygeeks actually I got it compiling and working on Alpine with no switches at all. I just set a source only version in the Gemfile as suggested here.
The argument is so you don't have to rely on all that. How about you provide more information instead because the broad statements made provide me with no way to validate this so we can release Alpine images with rubyracer. Such as: Versions, musl version, Alpine version (we use edge here and only edge...) are you sure it actually compiled and works as you think it does? The latter part isn't me trying to say you don't know how it works, it's me saying, it was a week before we could reliably trigger a segfault on Alpine.
Sure. The only thing I know is that in our case it compiles and all specs pass in a relatively large Rails app (using source only versions of libv8 as previously suggested). Whether it will segfault in a week I can't say. Here's some more info:
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.2.3
PRETTY_NAME="Alpine Linux v3.2"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
musl-1.1.9-r5
libv8 (= 3.16.14.6)
therubyracer (0.12.1)
So, no we're not using edge Alpine.
Hmmmm... that's the same versions we tried with our Discourse image that ended up segfaulting on Musl here is where we get the segfault: https://github.com/discourse/discourse/blob/a8edc982762d14bd01dc0b2964909c1fb6103deb/lib/pretty_text.rb#L176
I will try to recompile today.
@envygeeks You're right about that segfault. We get it too when compiling assets.
We're on ruby:
ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
From rbenv in our case.
Interestingly I get segmentation faults on Ubuntu now as well, possibly since locking the version to one that always compiles from source.
Here's what I get on Ubuntu:
/usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:99: [BUG] Segmentation fault at 0x00000000000000
ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0051 p:---- s:0186 e:000185 CFUNC :Run
c:0050 p:0008 s:0183 e:000182 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:99
c:0049 p:0006 s:0181 e:000180 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/error.rb:84 [FINISH]
c:0048 p:---- s:0177 e:000176 CFUNC :call
c:0047 p:---- s:0175 e:000174 CFUNC :TryCatch
c:0046 p:0015 s:0172 E:001448 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/error.rb:83
c:0045 p:0032 s:0169 E:002630 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:99
c:0044 p:0021 s:0165 e:000164 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:248 [FINISH]
c:0043 p:---- s:0163 e:000162 CFUNC :call
c:0042 p:---- s:0161 e:000160 CFUNC :HandleScope
c:0041 p:0015 s:0158 E:001cb8 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:245 [FINISH]
c:0040 p:---- s:0156 e:000155 CFUNC :call
c:0039 p:---- s:0154 e:000153 CFUNC :Locker
c:0038 p:0041 s:0151 E:0024c0 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:244
c:0037 p:0018 s:0147 e:000146 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:204
c:0036 p:0050 s:0143 E:002360 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1/lib/v8/context.rb:94
c:0035 p:0030 s:0137 e:000136 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:11
c:0034 p:0008 s:0135 e:000134 BLOCK /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:78 [FINISH]
c:0033 p:---- s:0132 e:000131 CFUNC :call
c:0032 p:---- s:0130 e:000129 CFUNC :Locker
c:0031 p:0023 s:0127 E:001128 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76
c:0030 p:0020 s:0122 E:001058 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:9 [FINISH]
c:0029 p:---- s:0117 e:000116 CFUNC :new
c:0028 p:0012 s:0112 e:000111 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/runtime.rb:44
c:0027 p:0011 s:0108 e:000107 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/module.rb:27
c:0026 p:0118 s:0104 e:000103 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/uglifier-2.2.1/lib/uglifier.rb:89
c:0025 p:0014 s:0100 e:000099 METHOD /home/john/Development/<snip>/lib/selective_assets_compressor.rb:5 [FINISH]
c:0024 p:---- s:0096 e:000095 CFUNC :new
c:0023 p:0422 s:0093 e:000091 CLASS /home/john/Development/<snip>/config/application.rb:91
c:0022 p:0019 s:0089 e:000088 CLASS /home/john/Development/<snip>/config/application.rb:19
c:0021 p:0111 s:0087 e:000086 TOP /home/john/Development/<snip>/config/application.rb:18 [FINISH]
c:0020 p:---- s:0085 e:000084 CFUNC :require
c:0019 p:0018 s:0081 e:000080 TOP /home/john/Development/<snip>/config/environment.rb:2 [FINISH]
c:0018 p:---- s:0079 e:000078 CFUNC :require
c:0017 p:0025 s:0075 e:000074 BLOCK config.ru:4 [FINISH]
c:0016 p:---- s:0073 e:000072 CFUNC :instance_eval
c:0015 p:0035 s:0070 e:000069 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.4.5/lib/rack/builder.rb:51 [FINISH]
c:0014 p:---- s:0065 e:000064 CFUNC :new
c:0013 p:0013 s:0062 E:0010e8 EVAL config.ru:1 [FINISH]
c:0012 p:---- s:0060 e:000059 CFUNC :eval
c:0011 p:0100 s:0054 e:000053 LAMBDA /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn.rb:44 [FINISH]
c:0010 p:---- s:0050 e:000049 CFUNC :call
c:0009 p:0081 s:0047 e:000044 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696
c:0008 p:0209 s:0042 E:000180 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:569
c:0007 p:0016 s:0038 e:000037 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:589
c:0006 p:0103 s:0026 e:000025 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:487
c:0005 p:0071 s:0019 E:001758 METHOD /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:137
c:0004 p:0205 s:0016 E:001aa8 TOP /usr/local/rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/unicorn-4.3.1/bin/unicorn:121 [FINISH]
c:0003 p:---- s:0010 e:000009 CFUNC :load
c:0002 p:0135 s:0006 E:001148 EVAL /usr/local/rbenv/versions/2.1.6/bin/unicorn:23 [FINISH]
c:0001 p:0000 s:0002 E:001738 TOP [FINISH]
any update on this about the fix to get alpine and rubyracer playing together ? Thanks
same error, any updates on this ?
I'd recommend using the mini_racer
runtime https://github.com/discourse/mini_racer for compiling assets.
@cowboyd we do! We switched to mini_racer for both Discourse and our own for musl-c based builds.
@envygeeks any issues with libv8?
@cowboyd switching to mini_racer, and less still require therubyracer to compile assets, how to make less work with mini_racer ?
bundle exec rake assets:precompile --trace
(in /home/app)
[WARNING] Please install gem 'therubyracer' to use Less.
rake aborted!
LoadError: cannot load such file -- v8
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/app/gems/gems/less-2.6.0/lib/less/java_script/v8_context.rb:2:in `<top (required)>'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/app/gems/gems/less-2.6.0/lib/less/java_script.rb:9:in `default_context_wrapper'
/home/app/gems/gems/less-2.6.0/lib/less/java_script.rb:17:in `context_wrapper'
/home/app/gems/gems/less-2.6.0/lib/less/loader.rb:13:in `initialize'
/home/app/gems/gems/less-2.6.0/lib/less.rb:14:in `new'
/home/app/gems/gems/less-2.6.0/lib/less.rb:14:in `<module:Less>'
/home/app/gems/gems/less-2.6.0/lib/less.rb:9:in `<top (required)>'
Less should use execjs and then this would not be a problem
On Tuesday, 14 June 2016, Dylan Wang notifications@github.com wrote:
@cowboyd https://github.com/cowboyd switching to mini_racer, and less still require therubyracer to compile assets, how to make less work with mini_racer ?
bundle exec rake assets:precompile --trace (in /home/app) [WARNING] Please install gem 'therubyracer' to use Less. rake aborted! LoadError: cannot load such file -- v8 /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in
require' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in
block in require' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:inload_dependency' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in
require' /home/app/gems/gems/less-2.6.0/lib/less/java_script/v8_context.rb:2:in<top (required)>' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in
require' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:inblock in require' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in
load_dependency' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:inrequire' /home/app/gems/gems/less-2.6.0/lib/less/java_script.rb:9:in
default_context_wrapper' /home/app/gems/gems/less-2.6.0/lib/less/java_script.rb:17:incontext_wrapper' /home/app/gems/gems/less-2.6.0/lib/less/loader.rb:13:in
initialize' /home/app/gems/gems/less-2.6.0/lib/less.rb:14:innew' /home/app/gems/gems/less-2.6.0/lib/less.rb:14:in
module:Less' /home/app/gems/gems/less-2.6.0/lib/less.rb:9:in `<top (required)>'— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cowboyd/therubyracer/issues/378#issuecomment-225846918, or mute the thread https://github.com/notifications/unsubscribe/AAAUXTzzkZC1d4TWmOAkjFdmZv9bVxdfks5qLogmgaJpZM4Fkee_ .
Uh.. Less not using execjs seems to be a known issue... https://github.com/cowboyd/less.rb/issues/11
@ignisf @SamSaffron yeh, I have node and execjs but none of them working with less
Ok, I'm getting the same segfault (I guess). Seems it comes up when trying to compile the uglifier gem (Full error message)
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99: [BUG] Segmentation fault at 0x00000000000000
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0017 p:---- s:0055 e:000054 CFUNC :Run
c:0016 p:0009 s:0052 e:000051 BLOCK /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99
c:0015 p:0006 s:0050 e:000049 BLOCK /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/error.rb:84 [FINISH]
c:0014 p:---- s:0046 e:000045 CFUNC :TryCatch
c:0013 p:0017 s:0043 E:0017f0 METHOD /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/error.rb:83
c:0012 p:0039 s:0040 E:000808 BLOCK /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99
c:0011 p:0023 s:0036 e:000035 BLOCK /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:248 [FINISH]
c:0010 p:---- s:0034 e:000033 CFUNC :HandleScope
c:0009 p:0017 s:0031 E:0006e0 BLOCK /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:245 [FINISH]
c:0008 p:---- s:0029 e:000028 CFUNC :Locker
c:0007 p:0045 s:0026 E:000608 METHOD /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:244
c:0006 p:0022 s:0022 e:000021 METHOD /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:204
c:0005 p:0055 s:0018 E:0004b8 METHOD /usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:94
c:0004 p:0013 s:0012 e:000011 BLOCK test.rb:3 [FINISH]
c:0003 p:---- s:0009 e:000008 CFUNC :open
c:0002 p:0040 s:0005 E:000378 EVAL test.rb:3 [FINISH]
c:0001 p:0000 s:0002 E:000a30 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------
test.rb:3:in `<main>'
test.rb:3:in `open'
test.rb:3:in `block in <main>'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:94:in `eval'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:204:in `enter'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:244:in `lock_scope_and_enter'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:244:in `Locker'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:245:in `block in lock_scope_and_enter'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:245:in `HandleScope'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:248:in `block (2 levels) in lock_scope_and_enter'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99:in `block in eval'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/error.rb:83:in `try'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/error.rb:83:in `TryCatch'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/error.rb:84:in `block in try'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99:in `block (2 levels) in eval'
/usr/local/bundle/gems/therubyracer-0.12.2/lib/v8/context.rb:99:in `Run'`
Steps to reproduce:
gem install libv8 -v "3.16.14.14"
gem install therubyracer -- --use-system-libraries
(installs 0.12.2)gem install uglifier
(installs 3.0.0)require 'uglifier'; Uglifier.new
Alternatively it is possible to reproduce the problem by just evaluating the uglifier source - see linked gist. I've narrowed down the problem to the last 430 lines of code or so.
Everything compiles fine, and evaluating js also works fine for "normal" cases...
@envygeeks How did you get mini_racer installed on alpine? It requires libv8 v5.x, which I can't get to build on alpine, do to weird problems like this:
current directory: /usr/local/bundle/gems/libv8-5.1.281.59.0/ext/libv8
/usr/local/bin/ruby -r ./siteconf20160702-3899-b1wjcf.rb extconf.rb
creating Makefile
Running: gclient root
v8/tools/mb (ERROR)
----------------------------------------
[0:02:55] Started.
[0:02:55]
________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://chromium.googlesource.com/chromium/src/tools/mb.git /usr/local/bundle/gems/libv8-5.1.281.59.0/vendor/v8/tools/_gclient_mb_nMNhOU' in '/usr/local/bundle/gems/libv8-5.1.281.59.0/vendor'
[0:02:55] Cloning into '/usr/local/bundle/gems/libv8-5.1.281.59.0/vendor/v8/tools/_gclient_mb_nMNhOU'...
[0:03:00] fatal: unable to access 'https://chromium.googlesource.com/chromium/src/tools/mb.git/': Couldn't resolve host 'chromium.googlesource.com'
And before you point out the obvious: Yes, the system has a network connection. The git command succeeds fine when run in a command line on its own.
Solving this might help: https://github.com/cowboyd/libv8/issues/221
@averell23 we package our own v8 for our Alpine and Ubuntu images because v8 lags considerably on most distro's.
@envygeeks you don't have a link to a Dockerfile by any chance? ;-) Anyway, I thought that the rubyracer would use the bundled v8 version from the libv8 gem anyway (?)
@envygeeks, are you able to share your script for building v8 on Alpine linux?
i'm guessing @envygeeks switched to ubuntu as base image rather than actually fixing it on alpine https://github.com/envygeeks/docker/blob/master/repos/discourse/Dockerfile
seeing a pattern of ppl giving up on alpine and using ubuntu instead:
https://github.com/cowboyd/libv8/issues/221
I'm trying to put together a base-rails Alpine based container for our app. The ExecJS is giving me fits trying to run libv8. I was hoping to use V8 with mini-racer on Alpine 3.4...
https://github.com/cowboyd/libv8/issues/198#issuecomment-158365247
I decided to go ahead with Ubuntu as Docker base image because I had some odd character encoding issues with the combination Ruby + Alpine Linux. After one day debugging I couldn't resolve the encoding issues even by setting all kind of ENV variables to UTF-8. Libv8 works fine on Ubuntu!
@sbimikesmullin that's our public image, https://talk.jekyllrb.com uses a private Alpine image we've not made public yet that uses @SamSaffron's bad ass Miniracer as much as it can with some patches in a few places (though I hear 1.7? Can't remember which version it started in) uses MiniRacer partially already.
@envygeeks, I'm glad to hear that mini_racer with the fresher version of libv8 work on Alpine!. I'm still unable to automate testing on it :/. You should be taking the HEAD version of mini_racer for a spin, too. Now would be a great time to do so, as they're gearing up for a release.
Did anyone find a workaround for this issue?
I'm trying to run assets:precompile
using 'mini_racer', '~> 0.1.7'
and 'libv8', '~> 5.3', '>= 5.3.332.38.3'
, but I'm getting this:
rake aborted!
LoadError: Error relocating /usr/local/bundle/gems/mini_racer-0.1.7/lib/mini_racer_extension.so: __fprintf_chk: symbol not found - /usr/local/bundle/gems/mini_racer-0.1.7/lib/mini_racer_extension.so
/usr/local/bundle/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
/usr/local/bundle/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
/usr/local/bundle/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/bundle/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
/usr/local/bundle/gems/mini_racer-0.1.7/lib/mini_racer.rb:2:in `<top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require'
/erp/config/application.rb:6:in `<top (required)>'
/erp/Rakefile:4:in `require'
/erp/Rakefile:4:in `<top (required)>'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:687:in `raw_load_rakefile'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/bundle/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/usr/local/bundle/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/usr/local/bundle/bin/rake:17:in `load'
/usr/local/bundle/bin/rake:17:in `<top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `<main>'
The command '/bin/sh -c RAILS_ENV=production bundle exec rake assets:precompile --trace' returned a non-zero code: 1
Hello @Strund3r,
The error you are experiencing is due to libv8
being linked against glibc
and Alpine shipping only musl
. The difficulty of running libv8
on Alpine is a known issue (https://github.com/cowboyd/libv8/#use-with-different-standard-c-libraries) that is still waiting for me (or preferably a kind contributor) to spend some time on (see https://github.com/cowboyd/libv8/issues/221).
Hey @ignisf,
We're running into some problems with this too. Would you be interested in sponsorship to get therubyracer working on Alpine?
Just wanted to contribute what i've learned today while researching this issue, seems it is possible, and there are some current docker images you can base from.
ENV LIBV8_MAJOR 5.3.332.38
ENV LIBV8_VERSION 5.3.332.38.3-x86_64-linux
ENV LIBV8_MAJOR 3.16
ENV LIBV8_VERSION 3.16.14.17-x86_64-linux
Both built FROM ruby:2.4.0-alpine
Looking at the latter:
⇒ docker run --rm usualoma/ruby-with-therubyracer:2.4.0-alpine ruby -e 'require "v8"; puts V8::Context.new.eval("7 * 6")'
42
Hopefully this helps some people out/saves some headaches!
@alias1 FYI, we also had a basic v8 setup working in alpine based on the above, but we're getting segfaults when trying to use more complex JS libs - aka less-rails.
If someone has that working correctly, I'd be super interested. In the meantime we're using a fork of less.rb call less-execjs and adding some of our own code to integrate w/ sprockets/rails.
for noobs like me: just an update for all those who come here struggling to get ruby or node running in alpine
we basically settled on two base images that are already working:
FROM ruby:2.4-alpine
and
FROM mhart/alpine-node:6
together with a script called dumb-init
which properly forwards signals (like CTRL+C) to the running container process. something like this:
FROM mhart/alpine-node:6
WORKDIR /home/app
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.3/dumb-init_1.1.3_amd64 /usr/bin/dumb-init
RUN chmod +x /usr/bin/dumb-init \
# process will run as non-root
&& adduser -D app
USER app
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node"]
don't ask me how it works, i don't actually know. but if you're like we were just trying to build your own from-scratch container for alpine and node.js, this may be a time saver.
for static bindings, we took to building dependencies (like npm modules and ruby gems) INSIDE the container, using an ONBUILD
step that looks for a prebundle.sh
script to execute. some may be tempted to bundle install
outside and copy only a few things in like vendor/
directory--but that leads to run-time segfaults and other surprises.
if you're hardcore and intent on working out the specific details unaddressed here, disregard this reply.
@mwarkentin Yup.. I see your pain now.. have just hit the same issue myself :p
k, so I have some updates.
I've released a prerelease version of libv8 5.7 (compatible with mini_racer) that runs on Alpine (cc @Strund3r). Still one needs to use a source version. gem install libv8 --platform=ruby
I've taken a look at v8 3.16 on Alpine as well. I'm getting a SEGFAULT during the build process. More precisely -- in the mksnapshot
utility. Here's the backtrace I managed to extract from the coredump:
(gdb) bt
#0 0x000055de676518a0 in v8::internal::PagedSpace::AdvanceSweeper(long) ()
#1 0x000055de67651a40 in v8::internal::PagedSpace::SlowAllocateRaw(int) ()
#2 0x000055de6748e870 in v8::internal::Heap::AllocatePartialMap(v8::internal::InstanceType, int) ()
#3 0x000055de67493e16 in v8::internal::Heap::CreateInitialMaps() ()
#4 0x000055de6749ccea in v8::internal::Heap::SetUp(bool) ()
#5 0x000055de67502c95 in v8::internal::Isolate::Init(v8::internal::Deserializer*) ()
#6 0x000055de673d0207 in v8::EnsureInitializedForIsolate(v8::internal::Isolate*, char const*) ()
#7 0x000055de673ea462 in v8::Context::New(v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Value>) ()
#8 0x000055de673cdad9 in main ()
The worst part is that this is a heisenbug that disappears whenever I enable debugging. :(
Yeap... Can confirm gem install libv8 --verbose --version=3.16.14.18 --no-ri --no-rdoc -- --enable-debug
runs successfully inside an Alpine 3.5 container.
If you need to use trr in a project on Alpine, for the time being my workaround is:
Gemfile:
gem 'libv8', '= 3.16.14.18'
gem 'therubyracer'
Then, execute bundle config build.libv8 --enable-debug
before running bundle install
. It will run slow due to v8's debug build.
Any suggestions on the SEGFAULT in release mode are welcome. I'm out of ideas for now... 😟
As a side note, trr cannot be compiled with Ruby from rbenv on Alpine:
/home/vagrant/.rbenv/versions/2.3.4/include/ruby-2.3.0/ruby/missing.h:166:29: error: 'int isinf(double)' conflicts with a previous declaration
RUBY_EXTERN int isinf(double);
Hi everyone,
I was looking if there was anything new about this issue and I found this:
I didn't try it yet, but, maybe, can it be of some help?
@Strund3r honestly a much better effort is migrating to mini_racer which should work on alpine
It is a gigantic effort to update trr to latest libv8 as it stands it is the equivalent of running Chrome 31 that was released 2013-11-12
@strund3r I tried alpine-pkg-glibc and I had no luck with ruby-2.3.1 alpine 3.4 therubyracer 0.12.3 and libv8 3.14.16.19.
I recently needed to get a Rails app running on Docker with Alpine 3.7 (Ruby 2.3.6) and encountered the issue described here, and had pretty much thrown in the towel and decided that the debug build of libv8 was the best I could do. But after chasing down some references based on where mksnapshot
blew up consistently once I was able to poke at it with gdb, I ended up with the following conclusions, and what may be a better workaround:
-fno-delete-null-pointer-checks
to the libv8 build, which got it past the mksnapshot
segfault. I was compiling libv8 3.16.14.19, but the same has worked for a couple of other versions I've tried since then.-O2
, thinking that perhaps the first workaround addressed some, but not all, of the optimization issues. That allowed the asset compilation to succeed, and the image build to complete.There are other ways to do it, but the way I passed these flags was as part of my bundle install
command, e.g.:
CXXFLAGS="-fno-delete-null-pointer-checks -O2" bundle install ...
Although it will likely incur some performance penalty as opposed to -O3
, it is still far better than the debug build's -O0
. Hopefully this will help others who have run into this - I found it quite frustrating, and would be interested to hear any feedback regarding this workaround.