55 Minutes

Welcome to the 55 Minutes blog.
55 Minutes is a web development consultancy in San Francisco building apps for design-led businesses and startups. On this blog we discuss the technology tools of our trade: Ruby on Rails, Django, Sass, OS X, and more.

Fixing a Segmentation Fault in Ruby 1.9.3

If you’ve compiled Ruby 1.9.3-p0 using rvm or ruby-build, and you also have MacPorts, you may run into a segmentation fault when initiating a TLS connection. Here’s a fix.

Update, February 17, 2012: This is still an issue with Ruby 1.9.3-p125 when compiled via rbenv/ruby-build. The same fix applies; see below.

If your Ruby installation is affected, it is very easy to crash the interpreter by using TLS. We were bitten by this bug when our app attempted to send email via TLS-enabled SMTP. Even a trivial Gemfile can trigger a segmentation fault. Bundler 1.1.rc.7 and Rails 3.2.0.rc2 now create a Gemfile so that it starts with an https URL, like this:

# A sample Gemfile
source "https://rubygems.org"

gem "rails"

Run bundle install on this simple Gemfile with Ruby 1.9.3-p0 and you might be greeted by this nasty error (edited for brevity):

$ bundle install
Fetching gem metadata from [https://rubygems.org/.](https://rubygems.org/.)
net/http.rb:799: [BUG] Segmentation fault
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

-- Control frame information -----------------------------------------------
c:0041 p:---- s:0225 b:0225 l:000224 d:000224 CFUNC  :connect
c:0040 p:0011 s:0222 b:0222 l:000c90 d:000221 BLOCK  net/http.rb:799

It turns out that this crash, like another recent Ruby headache, has something to do with MacPorts. Chris Irish explains the problem in detail, as it occurs with Ruby 1.9.2-p290. At 55 Minutes we encountered it on two different Macs, both running Ruby 1.9.3-p0.

The solution is to recompile Ruby using the --with-openssl-dir=/opt/local flag. Here’s how to do it (these instructions assume you have the openssl port installed in the default /opt/local location; in my case it is openssl version 1.0.0e):

rbenv + ruby-build

CONFIGURE_OPTS="--with-openssl-dir=/opt/local" rbenv install 1.9.3-p0


rvm install ruby-1.9.3 --with-openssl-dir=/opt/local --with-iconv-dir=/opt/local
comments powered by Disqus