Ruby 1.9.2 Segmentation Fault and OpenSSL

by Irish on September 2, 2011

In one of my current project, whenever I ran a rake task that did a net/http request it was causing segmentation faults.

$ bundle exec rake test:task
$ /Users/cirish/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:678: [BUG] Segmentation fault
ruby 1.9.2 (2011-06-30 patchlevel 290) [i686-darwin10.8.0]

And it seems whenever I get a segmentation fault the first place I need to look is at OpenSSL. I’ve had similar problems with seg faults and openssl in the past, namely this OpenSSL Bus Error that I was getting on Ruby 1.8.7.

If you read that post you’ll see this happened because I use MacPorts and have OpenSSL installed through it, in addition to a local OS X version. To get Ruby to be happy, you have to point your Ruby install to the correct version at installation time. So remove the bad install

$ rvm remove ruby-1.9.2

And reinstall

$ rvm install ruby-1.9.2 --with-openssl-dir=/opt/local --with-iconv-dir=$rvm_path/usr

Which I forgot to do with my Ruby 1.9.2 install after upgrading OS X versions. That last bit about iconv isn’t directly related, but I have inconv package installed to RVM, you can read about that here RVM Iconv.

Also, this Phusion blog post REE 1-8-7-2011-03-released mentions problems with OpenSSL and MacPorts. Moral of the story… use HomeBrew? Dunno, but I’ll probably start using it when I upgrade my laptop.

{ 13 comments… read them below or add one }

Sugel September 16, 2011 at 9:01 pm

For me the fix for this with an RVM version of ruby is to install it with the RVM OpenSSL package .In particular I used the following to install ruby 1.8.7-p174 .rvm package install iconv.rvm package install openssl.rvm install 1.8.7-p174 –with-openssl-dir HOME .rvm usr –with-iconv-dir rvm path usr…

Reply

Peter Degen-Portnoy November 17, 2011 at 5:47 pm

Chris, thanks for posting this. After wading through a fair number of bug reports, your instructions were clear, concise and correct!

Reply

Cynical Grinch December 5, 2011 at 1:31 pm

Your delete command is wrong. It should be:

$ rvm remove ruby-1.9.2

Reply

Irish December 5, 2011 at 2:06 pm

Yep, thanks for the catch, post updated.

Reply

Tim December 21, 2011 at 3:04 pm

Does this work with Homebrew? According to https://github.com/carlhuda/bundler/issues/1596 we need openssl 1.0, but it looks like Homebrew only has openssl 0.9.8r

Reply

Irish December 21, 2011 at 3:12 pm

Hey Tim, I’m not sure as I’m not currently using Homebrew. From the sound of that ticket, perhaps OpenSSL 1.0 is only a requirement of Ruby 1.9.3… But I’m not really sure.

Reply

Tim December 21, 2011 at 3:24 pm

No problem. I got it working with macports :-) Thanks for the blog post!

Reply

Mark Lanett December 27, 2011 at 5:23 pm

Thanks for the tips. This is my clean install:

1
2
3
4
5
6
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.rvm/bin # keep MacPorts out of PATH during compile
rvm pkg install iconv
rvm pkg install openssl
rvm install ruby-1.9.2 –with-openssl-dir=~/.rvm/usr –with-iconv-dir=~/.rvm/usr
rvm 1.9.2
ruby -ropenssl -e ‘p OpenSSL::Digest::Digest.new(“sha256″)’ # verify OpenSSL works

Reply

Dano Lee January 27, 2012 at 1:17 am

rvm install ruby-1.9.3-head -C –with-gcc=clang,–with-openssl-dir=~/.rvm/usr,–with-iconv-dir=~/.rvm/usr

the above worked for me. Thanks!

Reply

Derek February 11, 2012 at 2:23 am

This works with Ruby 1.9.3 on Snow Leopard.

Thanks Mark!

Reply

Dan Cartoon February 11, 2012 at 12:58 pm

This worked for me as well. Thanks!

Reply

Francisco January 25, 2012 at 1:35 pm

Thank you very much Irish!
Worked perfect for me!

Reply

Tim January 13, 2012 at 1:38 pm

Thank you Mark. That saved me a lot of time and worked on Mac OSX 10.7.2

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: