Skip to content

Instantly share code, notes, and snippets.

@plentz
Created March 10, 2011 03:20
Show Gist options
  • Save plentz/863523 to your computer and use it in GitHub Desktop.
Save plentz/863523 to your computer and use it in GitHub Desktop.
easy way to get a ruby segmentation fault
~/Projects/opensource $ rails -v
ruby Rails 3.0.5
~/Projects/opensource $ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
~/Projects/opensource $ rails new foo
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/fixtures
create test/functional
create test/integration
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
~/Projects/opensource $ cd foo/
~/Projects/opensource/foo $ mate Gemfile
~/Projects/opensource/foo $ cat Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'jquery-rails'
gem 'pg'
~/Projects/opensource/foo $ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.5)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.15)
Using actionmailer (3.0.5)
Using arel (2.0.9)
Using activerecord (3.0.5)
Using activeresource (3.0.5)
Using bundler (1.0.10)
Using thor (0.14.6)
Using railties (3.0.5)
Using rails (3.0.5)
Using jquery-rails (0.2.7)
Using pg (0.10.1)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
~/Projects/opensource/foo $ rails generate jquery:install
remove public/javascripts/controls.js
remove public/javascripts/dragdrop.js
remove public/javascripts/effects.js
remove public/javascripts/prototype.js
fetching jQuery (1.5)
create public/javascripts/jquery.js
create public/javascripts/jquery.min.js
fetching jQuery UJS adapter (github HEAD)
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
-- control frame ----------
c:0043 p:---- s:0216 b:0216 l:000215 d:000215 CFUNC :connect
c:0042 p:0011 s:0213 b:0213 l:0007e0 d:000212 BLOCK /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678
c:0041 p:0031 s:0211 b:0211 l:000210 d:000210 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44
c:0040 p:0026 s:0199 b:0199 l:000198 d:000198 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87
c:0039 p:0444 s:0193 b:0193 l:0007e0 d:0007e0 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678
c:0038 p:0011 s:0185 b:0185 l:000184 d:000184 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637
c:0037 p:0048 s:0182 b:0182 l:000181 d:000181 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626
c:0036 p:0646 s:0179 b:0179 l:000178 d:000178 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:306
c:0035 p:0024 s:0159 b:0159 l:000158 d:000158 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:769
c:0034 p:0047 s:0153 b:0153 l:000cf0 d:000152 BLOCK /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:203
c:0033 p:---- s:0151 b:0151 l:000150 d:000150 FINISH
c:0032 p:---- s:0149 b:0149 l:000148 d:000148 CFUNC :catch
c:0031 p:0491 s:0145 b:0145 l:000cf0 d:000cf0 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:201
c:0030 p:0328 s:0131 b:0131 l:000130 d:000130 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:146
c:0029 p:0022 s:0120 b:0120 l:000119 d:000119 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:671
c:0028 p:0096 s:0115 b:0115 l:000114 d:000114 METHOD /Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:33
c:0027 p:0103 s:0108 b:0108 l:000a88 d:000a88 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:77
c:0026 p:0031 s:0099 b:0099 l:000098 d:000098 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/jquery-rails-0.2.7/lib/generators/jquery/install/install_generator.rb:34
c:0025 p:0036 s:0096 b:0096 l:000095 d:000095 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/task.rb:22
c:0024 p:0071 s:0090 b:0090 l:000089 d:000089 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:118
c:0023 p:0012 s:0084 b:0084 l:000070 d:000083 BLOCK /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124
c:0022 p:---- s:0080 b:0080 l:000079 d:000079 FINISH
c:0021 p:---- s:0078 b:0078 l:000073 d:000077 IFUNC
c:0020 p:---- s:0076 b:0076 l:000075 d:000075 CFUNC :each
c:0019 p:---- s:0074 b:0074 l:000073 d:000073 CFUNC :map
c:0018 p:0023 s:0071 b:0071 l:000070 d:000070 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124
c:0017 p:0152 s:0068 b:0068 l:000067 d:000067 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/group.rb:226
c:0016 p:0102 s:0059 b:0059 l:000058 d:000058 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/base.rb:389
c:0015 p:0128 s:0053 b:0053 l:000052 d:000052 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/generators.rb:163
c:0014 p:0154 s:0045 b:0045 l:000044 d:000044 TOP /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands/generate.rb:10
c:0013 p:---- s:0042 b:0042 l:000041 d:000041 FINISH
c:0012 p:---- s:0040 b:0040 l:000039 d:000039 CFUNC :require
c:0011 p:0012 s:0036 b:0036 l:000020 d:000035 BLOCK /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239
c:0010 p:0005 s:0034 b:0034 l:000025 d:000033 BLOCK /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225
c:0009 p:0045 s:0032 b:0032 l:000031 d:000031 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596
c:0008 p:0041 s:0026 b:0026 l:000025 d:000025 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225
c:0007 p:0013 s:0021 b:0021 l:000020 d:000020 METHOD /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239
c:0006 p:0346 s:0016 b:0016 l:000015 d:000015 TOP /Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:17
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:0061 s:0006 b:0006 l:0014e8 d:001e08 EVAL script/rails:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0014e8 d:0014e8 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
script/rails:6:in `<main>'
script/rails:6:in `require'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:17:in `<top (required)>'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `block in require'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands/generate.rb:10:in `<top (required)>'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/generators.rb:163:in `invoke'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/jquery-rails-0.2.7/lib/generators/jquery/install/install_generator.rb:34:in `download_ujs_driver'
/Users/plentz/.rvm/gems/ruby-1.9.2-p180/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:77:in `get'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:33:in `open'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:671:in `open'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:769:in `buffer_open'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:306:in `open_http'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626:in `start'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:in `connect'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:in `block in connect'
/Users/plentz/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:in `connect'
-- C level backtrace information -------------------------------------------
[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
Abort trap
@plentz
Copy link
Author

plentz commented Mar 10, 2011

@plentz
Copy link
Author

plentz commented Mar 10, 2011

(It's really weird that the segfault only happens with gem 'pg')

@canma5
Copy link

canma5 commented Mar 12, 2011

Im also getting a segmentation fault but i dont have the 'gp' gem. I think is something related with 'https'. Im trying to do a get with an 'https' and I always have the same problem, even if i've tried with different ways to do the Get. Im gonna try using an older version of Ruby.

If you find a solution please let me know!

@pyrat
Copy link

pyrat commented Mar 16, 2011

I also have this problem!! Any solution would be much appreciated!

@canma5
Copy link

canma5 commented Mar 16, 2011

I think the problem is in the ruby libraries. I checked my code in another laptop and it works perfeclty. I tried to delete ruby versions but in the end i decided to format my mac and start from the beginning (i also had another weird erros...)

Now is working for me with Ruby 1.9.2 and Rails 3.0.5. Good luck!!

@bhavinkamani
Copy link

Hi, I am facing the same issue. Did anyone happen to find a solution? Thanks in advance

@mikeoligny
Copy link

Temporarily removing pg from Gemfile worked for me. =/

@jahio
Copy link

jahio commented Apr 21, 2011

Just to add to the body of knowledge here, I ran into this error as well and commented the pg gem from Gemfile as mikeoligny had suggested, and without re-running bundle install, everything worked exactly as it was supposed to. This is odd because I ran into the same segmentation fault error with Devise a few days ago, also with http.rb.

@jeromegwilson
Copy link

Same problem here too, also using PG but if I comment it out of the Gemfile (no re-bundle) it blows up with a 'where the heck is PG' type error :(

@wrtsprt
Copy link

wrtsprt commented May 13, 2011

@mikespokefire
Copy link

FWIW I'm also getting this error, Mac OS X Snow Leopard with PostgesQL84 installed via MacPorts, with gem 'pg' in my Gemfile it blows up with the same segfault, without it works perfectly.

@ged
Copy link

ged commented Jun 21, 2011

Is anyone who is experiencing this problem connecting using 'https'? I suspect this is caused by conflicting versions of OpenSSL: if the version that's linked against your libpq is not the same as the one linked against your Ruby stdlib's openssl extension, there's bound to be problems.

PS- on MacOS X, you can check the shared libraries something is linked against using 'otool':

$ otool -L ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.4.0/openssl.bundle 
/Users/mgranger/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.4.0/openssl.bundle:
/Users/mgranger/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.1.9.1.dylib (compatibility version 1.9.1, current version 1.9.1)
/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)

$ otool -L /opt/local/lib/postgresql90/libpq.5.dylib 
/opt/local/lib/postgresql90/libpq.5.dylib:
/opt/local/lib/postgresql90/libpq.5.dylib (compatibility version 5.0.0, current version 5.3.0)
/opt/local/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)  <-- OOPS
/opt/local/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

@jeromewilson
Copy link

Here's my results from otool:

/Users/abailey/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.7.0/openssl.bundle:
/Users/abailey/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.1.9.1.dylib (compatibility version 1.9.1, current version 1.9.1)
/Users/abailey/.rvm/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/Users/abailey/.rvm/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)

/opt/local/lib/postgresql91/libpq.5.4.dylib:
/opt/local/lib/postgresql91/libpq.5.dylib (compatibility version 5.0.0, current version 5.4.0)
/opt/local/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)

Looks like you're spot on!

@ged
Copy link

ged commented Jun 21, 2011

Okay, thanks @jeromewilson. Anybody else?

If this is indeed the problem, then I should probably try to detect it in the extconf, or ideally at runtime, and output a warning. There's a ticket open in the 'pg' bugtracker for this issue; comments and/or suggestions are welcomed either here or there.

@k504866430
Copy link

Not sure if this is of any help but I had the same issue and the otool just kept pointing me to different libssl versions every time. I just copy pasted the gem 'pg', :require => 'pg' to the bottom of the Gemfile and it worked.

Hope it helps!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment