Ruby installation on RHEL works, and then starts segfaulting - ruby

We have server which came with RHEL 5.8, unregistered - so no yum. We compiled and installed Ruby directly. It works - and then a few days later ruby programs start segfaulting. Can anyone suggest where to start looking for this error?
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1161: [BUG] Segmentation fault
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0008 p:---- s:0021 b:0021 l:000020 d:000020 CFUNC :require
c:0007 p:1596 s:0017 b:0017 l:000016 d:000016 CLASS /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1161
c:0006 p:0079 s:0015 b:0015 l:000014 d:000014 TOP /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:114
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :require
c:0003 p:0021 s:0006 b:0006 l:000005 d:000005 TOP <internal:gem_prelude>:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000d18 d:000d18 TOP
-- Ruby level backtrace information ----------------------------------------
<internal:gem_prelude>:1:in `<compiled>'
<internal:gem_prelude>:1:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:114:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1161:in `<module:Gem>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1161:in `require'
-- C level backtrace information -------------------------------------------
/usr/bin/ruby [0x525545] vm_dump.c:796
/usr/bin/ruby [0x569b96] error.c:258
/usr/bin/ruby(rb_bug+0xb3) [0x569d03] error.c:277
/usr/bin/ruby [0x4b1749] signal.c:633
/lib64/libpthread.so.0 [0x3a1700ebe0]
/usr/bin/ruby(st_lookup+0x26) [0x4b8136] st.c:333
/usr/bin/ruby [0x51c723] vm_method.c:374
/usr/bin/ruby [0x44bcef] object.c:2062
/usr/bin/ruby(rb_convert_type+0x5a) [0x44e87a] object.c:2083
/usr/bin/ruby(rb_string_value_ptr+0x27) [0x4c02c7] string.c:810
/usr/bin/ruby [0x56cabe] load.c:156
/usr/bin/ruby(rb_require_safe+0x20f) [0x56d6cf] load.c:550
/usr/bin/ruby [0x522a94] vm_insnhelper.c:404
/usr/bin/ruby [0x514697] insns.def:1018
/usr/bin/ruby [0x51ad48] vm.c:1236
/usr/bin/ruby(rb_iseq_eval+0x152) [0x51b292] vm.c:1464
/usr/bin/ruby [0x56c486] load.c:310
/usr/bin/ruby(rb_require_safe+0x6c6) [0x56db86] load.c:620
/usr/bin/ruby [0x522a94] vm_insnhelper.c:404
/usr/bin/ruby [0x514697] insns.def:1018
/usr/bin/ruby [0x51ad48] vm.c:1236
/usr/bin/ruby(rb_iseq_eval+0x152) [0x51b292] vm.c:1464
/usr/bin/ruby(ruby_process_options+0x325) [0x4b06c5] ruby.c:1116
/usr/bin/ruby(ruby_options+0x90) [0x4178b0] eval.c:73
/usr/bin/ruby [0x414985] main.c:38
/lib64/libc.so.6(__libc_start_main+0xf4) [0x3a1601d994]
/usr/bin/ruby [0x414889]
-- Other runtime information -----------------------------------------------
* Loaded script: /usr/bin/ruby
* Loaded features:
0 enumerator.so
1 /usr/local/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
2 /usr/local/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
Segmentation fault

A wild guess.
RHEL systems are by default configured to prelink shared libraries to a random address, once every 2 weeks.
Perhaps your copy of ruby doesn't work correctly when it is prelinked?
It starts working after a fresh build, then prelink is performed on all shared libraries, and it stops working until next fresh install.
You can find out whether the library is prelinked or not by running:
readelf -l encdb.so | grep LOAD | head -1
Un-prelinked library will have first load segment at 0. Prelinked library will have it as non-zero.
Update: this link suggest that Ruby indeed may not work with prelinking. Solution from there (copied for posterity):
Add -b /usr/bin/ruby to your /etc/prelink.conf file, this tells prelink to not touch the ruby interpreter.

Related

Ruby 2.6.5 and PostgreSQL pg-gem segmentation fault

From the console I cannot do any operation that touches the database. I get a Segmentation fault.
.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg.rb:56: [BUG] Segmentation fault at 0x0000000000000110
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
It is literally any operation that might need the database, including MyModel.new.
-- Control frame information -----------------------------------------------
c:0071 p:---- s:0406 e:000405 CFUNC :initialize
c:0070 p:---- s:0403 e:000402 CFUNC :new
c:0069 p:0016 s:0398 e:000397 METHOD /Users/xxx/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg.rb:56
c:0068 p:0107 s:0393 e:000392 METHOD /Users/xxx/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgres
I have uninstalled and reinstalled the pg gem. And rebuilt the database. And restarted PostgreSQL.
I have seen other people reporting the problem when running under Puma, but my configuration works under Puma, fails under console!
Edit for clarity:
Yes, using bundler.
Starting the rails console either with rails c or bundle exec rails c has the same effect (segfault) with same stack trace.
Gemfile.lock has pg (1.1.4)
I re-bundled, specifying a bundle path. The stack trace now has that bundle path, so I guess by default bundler was using the rbenv path.
As per https://github.com/ged/ruby-pg/issues/291, which is linked in the comments section of the question, adding gssencmode: disable to database.yml stops segmentation faults. I've added it under development and test environment options only, as I don't use OS X in other environments:
default: &default
adapter: postgresql
development:
<<: *default
gssencmode: disable
test:
<<: *default
gssencmode: disable
gssencmode was added in Postgresql 12:
gssencmode
This option determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server.
The underlying bug is tracked here https://www.postgresql.org/message-id/93f7379b-2e2f-db0c-980e-07ebd5de92ff%40crunchydata.com

therubyracer v8 init.so Segmentation fault

I'm running Centos 6.5, apache2 and ruby 2.1.2p95 and trying to start Puma server for my sinatra app. It continues to fail giving an extremely long output but it appears the real error is:
/usr/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/therubyracer-0.11.3/v8/init.so: [BUG] Segmentation fault at 0x0000000007fc90
here's a bigger chunk of the output:
-bash-4.1$ bundle exec puma -e staging
Puma starting in single mode...
* Version 2.9.1 (ruby 2.1.2-p95), codename: Team High Five
* Min threads: 0, max threads: 16
* Environment: staging
/usr/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/therubyracer-0.11.3/v8/init.so: [BUG] Segmentation fault at 0x0000000007fc90
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0042 p:-17562721875862 s:0153 e:000152 TOP [FINISH]
c:0041 p:---- s:0151 e:000150 CFUNC :require
c:0040 p:0023 s:0147 e:000146 TOP /usr/lib/ruby/gems/2.1.0/gems/therubyracer-0.11.3/lib/v8.rb:4 [FINISH]
c:0039 p:---- s:0145 e:000144 CFUNC :require
c:0038 p:0009 s:0141 e:000140 METHOD /usr/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:97 [FINISH]
c:0037 p:---- s:0138 e:000137 IFUNC
c:0036 p:---- s:0136 e:000135 IFUNC
I was using a newer version of therubyracer, but saw a post where someone suggested rolling back and that didn't work.
It also seems like this isn't always the error I'm getting. one time it was the sass gem that failed, but this was the most often
Ok, so I did figure out how to get around this and it was a good fix for me b/c I plan on deploying Node.js projects anyhow, but as Jan Strnádek sad in the comment above, the whole issue could be avoided by installing node.js
https://www.digitalocean.com/community/tutorials/how-to-install-and-run-a-node-js-app-on-centos-6-4-64bit
I then commented out therubyracer gem and any dependencies and bundle install again and the server started right up no problem.

require 'rspec/autorun' -- doesnt work for me

Can anyone tell me what I'm doing wrong?
~/ruby_programs$ rspec --version
3.0.3
~/ruby_programs$ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin10.0]
~/ruby_programs$ cat my_rspec.rb
require 'rspec/autorun'
describe "require 'rspec/autorun'" do
it 'should not cause this program to throw an error' do
true
end
end
~/ruby_programs$ rspec my_rspec.rb
.
Deprecation Warnings:
Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /Users/7stud/ruby_programs/my_rspec.rb:1:in `<top (required)>'.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Finished in 0.00159 seconds (files took 0.16241 seconds to load)
1 example, 0 failures
Here we go:
~/ruby_programs$ ruby my_rspec.rb
my_rspec.rb:3:in `<main>': undefined method `describe' for main:Object (NoMethodError)
That's because RSpec is missed. You should do the following:
require 'rspec/autorun'
RSpec.describe "require 'rspec/autorun'" do
it 'should not cause this program to throw an error' do
true
end
end
Try to execute the rspec using $ bundle exec rspec instead of rspec only

Embedding Ruby debugging and gems using

Embedding Ruby in C is poor documented part of Ruby programming. When I call Ruby from C code and I do something wrong on Ruby side I get error in this form:
<dummy toplevel>:17: [BUG] Segmentation fault
ruby 1.9.0 (2008-10-04 revision 19669) [i486-linux]
-- control frame ----------
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 CFUNC :require
c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP <dummy toplevel>:17
---------------------------
DBG> : ":0:in `require'"
-- backtrace of native function call (Use addr2line) --
0x231316
0x1515e7
0x15166a
0x1da144
0x8e6410
0x3ca46c
0x1530da
0x153473
0x15009b
0x156127
0x1566c6
0x21ef73
0x22b56a
0x22c4a5
0x80540fb
0x80544ee
0x3b6bd6
0x8049721
-------------------------------------------------------
My first question is if its possible to get more sophisticated error message? What does Use addr2line mean? Or how can I find from this stack trace, where is my error?
Second question is about using gems in embedded Ruby. When I use it in classic Ruby form require name_of_gem the gem is not found. When I use absolute path to one file gem its OK, but when gem is composed from more files I wasnt able to use it.

Getting the error "msvcrt-ruby18.dll is missing" when running watir scripts after installing rubyinstaller-1.9.2-p136

Installed rubyinstaller-1.9.2-p136 and ran the the following commands in the cmd prompt.
gem update --system
gem install watir.
The commands got executed successfully. But when i ran a ruby script with the following contents in it, i am getting the error "The program can't start because msvcrt-ruby18.dll is missing from your computer. Try reinstalling the program to fix this problem. " I tried reinstalling it multiple times, but no luck.
I google around and found the msvcrt-ruby18.dll file. But i don't know what i should do with it. Please help!
Contents of my ruby file:
require 'watir'
ie = Watir::IE.new
ie.goto('http://www.google.com')
You've probably installed some binary gems that was built against msvcrt-ruby18.dll. The solution is to
install DevKit so that you have an environment for building native code locally.
Uninstall the bad gem (which is causing this dialog when require'd)
Reinstall it, but force local compilation, i.e.
gem install gemname --platform=ruby
Did you try going to Ruby 1.8.6? I saw that recommended in the Google Groups for Watir.
Also, I saw a reference to that in an issues about this in a ruby forum thread, especially towards the bottom. If you are just getting started, then there probably isn't a need to support the newest version of Ruby, which has some issues with libraries compiled with previous versions of Ruby.
You can define a gem to be targeted at one version of Ruby (using gem
spec required_ruby_version attribute), however, you can't generate a
binary gem that target both 1.8.x and 1.9.x series of Ruby.
There are binary differences between 1.8.x and 1.9.x (different C-API,
different VM, etc) that made these pre-compiled extensions
incompatible.**
Apparently, Watir was built with 1.8.x. An alternative is to use Vapir, which is based on Watir but not backwards completely compatible because of changes in that branch.
Don't download the ruby18 version if you like to run wxRuby. What you get is this:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/wxruby-2.0.1-x86-mingw32/lib/wxruby2.so: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
-- control frame ----------
c:0011 p:-10361992 s:0034 b:0034 l:000033 d:000033 TOP
c:0010 p:---- s:0032 b:0032 l:000031 d:000031 CFUNC :require
c:0009 p:0013 s:0028 b:0028 l:000027 d:000027 METHOD <internal:lib/rubygems/custom_require>:29
c:0008 p:0011 s:0023 b:0023 l:000022 d:000022 TOP C:/Ruby192/lib/ruby/gems/1.9.1/gems/wxruby-2.0.1-x86-mingw32/lib/wx.rb:12
c:0007 p:---- s:0020 b:0020 l:000019 d:000019 FINISH
c:0006 p:---- s:0018 b:0018 l:000017 d:000017 CFUNC :require
c:0005 p:0073 s:0014 b:0014 l:000010 d:000013 BLOCK <internal:lib/rubygems/custom_require>:33
c:0004 p:0014 s:0011 b:0011 l:000010 d:000010 METHOD <internal:lib/rubygems/custom_require>:29
c:0003 p:0011 s:0006 b:0006 l:00175c d:002234 EVAL MinimalRuby.rb:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:00175c d:00175c TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
MinimalRuby.rb:1:in `<main>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:33:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/wxruby-2.0.1-x86-mingw32/lib/wx.rb:12:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
the gem (wxruby 19) downloaded and installed just fine. Of course, that doesn't mean it will necessarily run.
To fix this error, we need to register the autoit dll "AutoItX3.dll". In my machine the dll is located at C:\Ruby192\lib\ruby\gems\1.9.1\gems\rautomation-0.6.3\ext\AutoItX. So, you need to goto this folder in command prompt and execute "regsvr AutoItX3.dll". That fixed the problem

Resources