rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.67k stars 190 forks source link

Segfault with Musl-LibC on MRI inside of Alpine Linux. #378

Closed envygeeks closed 7 months ago

envygeeks commented 8 years ago
[BUG] Segmentation fault at 0x00000000000000
discourse_1  | ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux-musl]
discourse_1  | 
discourse_1  | -- Control frame information -----------------------------------------------
discourse_1  | c:0102 p:---- s:0399 e:000398 CFUNC  :RunWithTimeout
discourse_1  | c:0101 p:0011 s:0395 e:000394 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:97
discourse_1  | c:0100 p:0006 s:0393 e:000392 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/error.rb:84 [FINISH]
discourse_1  | c:0099 p:---- s:0389 e:000388 CFUNC  :call
discourse_1  | c:0098 p:---- s:0387 e:000386 CFUNC  :TryCatch
discourse_1  | c:0097 p:0015 s:0384 E:0006c0 METHOD /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/error.rb:83
discourse_1  | c:0096 p:0022 s:0381 E:002138 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:97
discourse_1  | c:0095 p:0021 s:0377 e:000376 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:248 [FINISH]
discourse_1  | c:0094 p:---- s:0375 e:000374 CFUNC  :call
discourse_1  | c:0093 p:---- s:0373 e:000372 CFUNC  :HandleScope
discourse_1  | c:0092 p:0015 s:0370 E:001180 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:245 [FINISH]
discourse_1  | c:0091 p:---- s:0368 e:000367 CFUNC  :call
discourse_1  | c:0090 p:---- s:0366 e:000365 CFUNC  :Locker
discourse_1  | c:0089 p:0041 s:0363 E:0019d8 METHOD /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:244
discourse_1  | c:0088 p:0018 s:0359 e:000358 METHOD /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:204
discourse_1  | c:0087 p:0050 s:0355 E:000d38 METHOD /usr/lib/ruby/gems/2.2.0/gems/therubyracer-0.12.2/lib/v8/context.rb:94
discourse_1  | c:0086 p:0141 s:0349 e:000348 BLOCK  /opt/discourse/lib/pretty_text.rb:175
discourse_1  | c:0085 p:0008 s:0345 e:000344 BLOCK  /opt/discourse/lib/pretty_text.rb:357 [FINISH]
discourse_1  | c:0084 p:---- s:0342 e:000341 CFUNC  :synchronize
discourse_1  | c:0083 p:0014 s:0339 e:000338 METHOD /opt/discourse/lib/pretty_text.rb:355
discourse_1  | c:0082 p:0015 s:0335 e:000334 METHOD /opt/discourse/lib/pretty_text.rb:152
discourse_1  | c:0081 p:0040 s:0328 e:000327 METHOD /opt/discourse/lib/pretty_text.rb:210
discourse_1  | c:0080 p:0017 s:0320 e:000319 METHOD /opt/discourse/app/models/post_analyzer.rb:12
discourse_1  | c:0079 p:0187 s:0314 e:000313 METHOD /opt/discourse/app/models/post.rb:176
discourse_1  | c:0078 p:0115 s:0307 e:000305 METHOD /opt/discourse/lib/post_creator.rb:161
discourse_1  | c:0077 p:0014 s:0301 e:000300 BLOCK  /opt/discourse/app/models/post.rb:411 [FINISH]
discourse_1  | c:0076 p:---- s:0299 e:000298 CFUNC  :instance_exec
discourse_1  | c:0075 p:0010 s:0296 e:000295 LAMBDA /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:443 [FINISH]
discourse_1  | c:0074 p:---- s:0292 e:000291 CFUNC  :call
discourse_1  | c:0073 p:0042 s:0287 e:000286 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:161 [FINISH]
discourse_1  | c:0072 p:---- s:0280 e:000279 CFUNC  :call
discourse_1  | c:0071 p:0012 s:0276 e:000275 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:501 [FINISH]
discourse_1  | c:0070 p:---- s:0273 e:000272 CFUNC  :each
discourse_1  | c:0069 p:0009 s:0270 e:000269 METHOD /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:501
discourse_1  | c:0068 p:0077 s:0265 e:000264 METHOD /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:86
discourse_1  | c:0067 p:0009 s:0257 E:000440 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/callbacks.rb:306
discourse_1  | c:0066 p:0030 s:0254 e:000253 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/timestamp.rb:57
discourse_1  | c:0065 p:0030 s:0250 e:000249 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/persistence.rb:484
discourse_1  | c:0064 p:0008 s:0246 e:000245 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/callbacks.rb:302 [FINISH]
discourse_1  | c:0063 p:---- s:0244 e:000243 CFUNC  :call
discourse_1  | c:0062 p:0036 s:0241 e:000239 METHOD /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:113
discourse_1  | c:0061 p:0017 s:0235 e:000234 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:552 [FINISH]
discourse_1  | c:0060 p:---- s:0232 e:000231 CFUNC  :call
discourse_1  | c:0059 p:0021 s:0228 e:000227 METHOD /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:502
discourse_1  | c:0058 p:0077 s:0223 e:000222 METHOD /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:86
discourse_1  | c:0057 p:0009 s:0215 E:000890 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/callbacks.rb:302
discourse_1  | c:0056 p:0007 s:0212 e:000211 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/persistence.rb:103
discourse_1  | c:0055 p:0021 s:0208 e:000207 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/validations.rb:51
discourse_1  | c:0054 p:0010 s:0204 e:000203 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/attribute_methods/dirty.rb:21
discourse_1  | c:0053 p:0011 s:0199 e:000198 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:268
discourse_1  | c:0052 p:0014 s:0197 e:000196 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:329
discourse_1  | c:0051 p:0069 s:0195 e:000194 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:199
discourse_1  | c:0050 p:0017 s:0191 e:000190 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:208
discourse_1  | c:0049 p:0014 s:0186 E:0016b8 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:326
discourse_1  | c:0048 p:0007 s:0182 E:002610 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:268
discourse_1  | c:0047 p:0012 s:0180 e:000179 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:283
discourse_1  | c:0046 p:0007 s:0177 E:001308 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:267
discourse_1  | c:0045 p:0027 s:0173 e:000172 METHOD /opt/discourse/lib/post_creator.rb:281
discourse_1  | c:0044 p:0013 s:0169 e:000168 BLOCK  /opt/discourse/lib/post_creator.rb:116 [FINISH]
discourse_1  | c:0043 p:---- s:0167 e:000166 CFUNC  :call
discourse_1  | c:0042 p:0015 s:0164 e:000163 BLOCK  /opt/discourse/lib/post_creator.rb:182
discourse_1  | c:0041 p:0069 s:0162 e:000161 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:199
discourse_1  | c:0040 p:0017 s:0158 e:000157 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:208
discourse_1  | c:0039 p:0013 s:0153 E:001cc8 METHOD /opt/discourse/lib/post_creator.rb:180
discourse_1  | c:0038 p:0014 s:0149 E:000200 METHOD /opt/discourse/lib/post_creator.rb:114
discourse_1  | c:0037 p:0134 s:0146 e:000145 METHOD (eval):16
discourse_1  | c:0036 p:0145 s:0133 e:000132 EVAL   (eval):29 [FINISH]
discourse_1  | c:0035 p:---- s:0126 e:000125 CFUNC  :eval
discourse_1  | c:0034 p:0033 s:0122 e:000121 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:46
discourse_1  | c:0033 p:0008 s:0118 e:000117 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:58 [FINISH]
discourse_1  | c:0032 p:---- s:0115 e:000114 CFUNC  :open
discourse_1  | c:0031 p:0046 s:0111 e:000110 METHOD /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:57
discourse_1  | c:0030 p:0009 s:0107 e:000106 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:36
discourse_1  | c:0029 p:0006 s:0105 e:000104 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:201
discourse_1  | c:0028 p:0019 s:0103 e:000102 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:209
discourse_1  | c:0027 p:0078 s:0097 e:000096 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:201
discourse_1  | c:0026 p:0017 s:0093 e:000092 METHOD /usr/lib/ruby/gems/2.2.0/gems/activerecord-4.1.10/lib/active_record/transactions.rb:208
discourse_1  | c:0025 p:0039 s:0088 E:0025c8 METHOD /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:35
discourse_1  | c:0024 p:0009 s:0084 e:000083 BLOCK  /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:26 [FINISH]
discourse_1  | c:0023 p:---- s:0081 e:000080 CFUNC  :each
discourse_1  | c:0022 p:0043 s:0078 e:000077 METHOD /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu/runner.rb:25
discourse_1  | c:0021 p:0033 s:0075 e:000074 METHOD /usr/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.5/lib/seed-fu.rb:29
discourse_1  | c:0020 p:0013 s:0070 e:000069 BLOCK  /opt/discourse/lib/tasks/db.rake:8 [FINISH]
discourse_1  | c:0019 p:---- s:0067 e:000066 CFUNC  :call
discourse_1  | c:0018 p:0028 s:0062 e:000061 BLOCK  /usr/lib/ruby/2.2.0/rake/task.rb:240 [FINISH]
discourse_1  | c:0017 p:---- s:0059 e:000058 CFUNC  :each
discourse_1  | c:0016 p:0113 s:0056 e:000055 METHOD /usr/lib/ruby/2.2.0/rake/task.rb:235
discourse_1  | c:0015 p:0075 s:0052 e:000051 BLOCK  /usr/lib/ruby/2.2.0/rake/task.rb:179
discourse_1  | c:0014 p:0014 s:0050 e:000049 METHOD /usr/lib/ruby/2.2.0/monitor.rb:211
discourse_1  | c:0013 p:0025 s:0047 e:000046 METHOD /usr/lib/ruby/2.2.0/rake/task.rb:172
discourse_1  | c:0012 p:0036 s:0040 e:000039 METHOD /usr/lib/ruby/2.2.0/rake/task.rb:165
discourse_1  | c:0011 p:0035 s:0035 e:000034 METHOD /usr/lib/ruby/2.2.0/rake/application.rb:150
discourse_1  | c:0010 p:0009 s:0028 e:000027 BLOCK  /usr/lib/ruby/2.2.0/rake/application.rb:106 [FINISH]
discourse_1  | c:0009 p:---- s:0025 e:000024 CFUNC  :each
discourse_1  | c:0008 p:0039 s:0022 e:000021 BLOCK  /usr/lib/ruby/2.2.0/rake/application.rb:106
discourse_1  | c:0007 p:0025 s:0020 e:000019 METHOD /usr/lib/ruby/2.2.0/rake/application.rb:115
discourse_1  | c:0006 p:0007 s:0016 e:000015 METHOD /usr/lib/ruby/2.2.0/rake/application.rb:100
discourse_1  | c:0005 p:0019 s:0013 e:000012 BLOCK  /usr/lib/ruby/2.2.0/rake/application.rb:78
discourse_1  | c:0004 p:0006 s:0011 e:000010 METHOD /usr/lib/ruby/2.2.0/rake/application.rb:176
discourse_1  | c:0003 p:0007 s:0007 e:000006 METHOD /usr/lib/ruby/2.2.0/rake/application.rb:75
discourse_1  | c:0002 p:0040 s:0004 E:0021f0 EVAL   /usr/bin/rake:33 [FINISH]
discourse_1  | c:0001 p:0000 s:0002 E:000f10 TOP    [FINISH]
cowboyd commented 8 years 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.

envygeeks commented 8 years ago

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.

envygeeks commented 8 years ago

As a sidenote @cowboyd I would love to try the new version if it's available.

cowboyd commented 8 years ago

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

johnae commented 8 years ago

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'
...
ignisf commented 8 years ago

@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?

johnae commented 8 years ago

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

ignisf commented 8 years ago

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

ignisf commented 8 years ago

(also, remove the use system libraries switch from the bundle config beforehand)

envygeeks commented 8 years ago

You need to use --use-system-libraries and skip the --with-system-v8

envygeeks commented 8 years ago

The whole point of skipping the latter is to get therubyracer to compile it's bundled v8 with musl.

johnae commented 8 years ago

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

envygeeks commented 8 years ago

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.

johnae commented 8 years ago

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.

envygeeks commented 8 years ago

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.

johnae commented 8 years ago

@envygeeks You're right about that segfault. We get it too when compiling assets.

johnae commented 8 years ago

We're on ruby:

ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]

From rbenv in our case.

johnae commented 8 years ago

Interestingly I get segmentation faults on Ubuntu now as well, possibly since locking the version to one that always compiles from source.

johnae commented 8 years ago

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]
salimane commented 8 years ago

any update on this about the fix to get alpine and rubyracer playing together ? Thanks

Ehekatl commented 8 years ago

same error, any updates on this ?

cowboyd commented 8 years ago

I'd recommend using the mini_racer runtime https://github.com/discourse/mini_racer for compiling assets.

envygeeks commented 8 years ago

@cowboyd we do! We switched to mini_racer for both Discourse and our own for musl-c based builds.

ignisf commented 8 years ago

@envygeeks any issues with libv8?

Ehekatl commented 8 years ago

@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)>'
SamSaffron commented 8 years ago

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: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/v8_context.rb:2:in <top (required)>' /home/app/gems/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:inrequire' /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.rb:9:indefault_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:ininitialize' /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:inmodule: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_ .

ignisf commented 8 years ago

Uh.. Less not using execjs seems to be a known issue... https://github.com/cowboyd/less.rb/issues/11

Ehekatl commented 8 years ago

@ignisf @SamSaffron yeh, I have node and execjs but none of them working with less

averell23 commented 8 years ago

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:

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

averell23 commented 8 years ago

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

ignisf commented 8 years ago

Solving this might help: https://github.com/cowboyd/libv8/issues/221

envygeeks commented 8 years ago

@averell23 we package our own v8 for our Alpine and Ubuntu images because v8 lags considerably on most distro's.

averell23 commented 8 years ago

@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 (?)

smebberson commented 7 years ago

@envygeeks, are you able to share your script for building v8 on Alpine linux?

sbimikesmullin commented 7 years ago

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!

envygeeks commented 7 years ago

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

ignisf commented 7 years ago

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

strund3r commented 7 years ago

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
ignisf commented 7 years ago

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

mneumegen commented 7 years ago

Hey @ignisf,

We're running into some problems with this too. Would you be interested in sponsorship to get therubyracer working on Alpine?

0xdevalias commented 7 years ago

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.

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!

mwarkentin commented 7 years ago

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

sbimikesmullin commented 7 years ago

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.

0xdevalias commented 7 years ago

@mwarkentin Yup.. I see your pain now.. have just hit the same issue myself :p

ignisf commented 7 years ago

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. :(

ignisf commented 7 years ago

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);
strund3r commented 7 years ago

Hi everyone,

I was looking if there was anything new about this issue and I found this:

alpine-pkg-glibc

I didn't try it yet, but, maybe, can it be of some help?

SamSaffron commented 7 years ago

@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

LanikSJ commented 6 years ago

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

levocode commented 6 years ago

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:

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.