loading...

Ruby Segmentation Fault When Running RSpec

andy profile image Andy Zhao (he/him) Updated on ・2 min read

So I've been getting this segmentation fault error, which from what I've been hearing and reading it's a low-level Ruby error. It happens when I run all specs via a bin command: bin/rspec. I've run into this error a few times now, and for whatever reason it's resolved itself in an hour or two. I'm not running any super memory-consuming tests, and given that our CI runs it just fine 100% of the time, I don't think it's the tests.

Here's a snippet of the log:

............................................................................................../Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/2.5.0/open-uri.rb:408: [BUG] Segmentation fault at 0x000070000dfbf4b0
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0080 p:---- s:0452 e:000451 CFUNC  :write
c:0079 p:---- s:0449 e:000448 CFUNC  :<<
c:0078 p:0011 s:0444 e:000443 METHOD /Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/2.5.0/open-uri.rb:408
c:0077 p:0012 s:0438 e:000437 BLOCK  /Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/2.5.0/open-uri.rb:353
c:0076 p:0007 s:0434 e:000433 METHOD /Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/2.5.0/net/protocol.rb:433
c:0075 p:0018 s:0429 e:000428 METHOD /Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/2.5.0/net/protocol.rb:424
c:0074 p:0166 s:0424 e:000423 METHOD /Users/andyzhao/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webmock-3.3.0/lib/webmock/http_lib_adapters/net_http_response.rb

I'm running macOS High Sierra 10.13.5 with 8 GB of RAM.

Here's are links to the last three crash report files via Google Drive if anyone's interested:
https://drive.google.com/file/d/1G7sPOquIDTHUTh-qhwJ7AKIgtaw7MNNh/view?usp=sharing

https://drive.google.com/file/d/1OIAhfZAtclNd2YZ6FG_zRYDYBd2eHG6p/view?usp=sharing

https://drive.google.com/file/d/1qeGIhKYAp1HlxK7LaijuB26AQt8NGjpL/view?usp=sharing

Discussion

pic
Editor guide
Collapse
katafrakt profile image
Paweł Świątkowski

It's really hard to tell. In my experience segmentation faults usually happen when there is something wrong with some C extension in some gem. But in your case it seems to come straight from Ruby core lib. Someone might have better idea, but to me it seems like one of those:

  • There is a problem with your Ruby installation (unlikely)
  • Some gem you used accessed some memory it should not, hence this odd backtrace – maybe post your Gemfile
  • Some other program running on your computer messed up something in memory

Not sure if that helps, but that's all I can think of at the moment.

Collapse
andy profile image
Andy Zhao (he/him) Author

Definitely helpful, thanks for the insight. I did reinstall my Ruby and rbenv recently to test something, and ever since then I've been getting that error.

I'm a bit skeptical about this, but it might also be because I upgraded my Mac to High Sierra...

Collapse
katafrakt profile image
Paweł Świątkowski

MacOS is actually notorious for breaking Ruby-related things on every upgrade, so you might be on to something. Just last week my colleague had to reinstall his system completely in order to make Ruby working again. He had other symptoms though, as far as I remember (something SSL-related).

Thread Thread
andy profile image
Andy Zhao (he/him) Author

Yikes. I'm going to be wiping my drive anyway, so while drastic, it might solve my issues. Maybe 2.5.1 will fare better with High Sierra, too.

Collapse
citizen428 profile image
Michael Kohl

I agree that your first step should be upgrading to Ruby 2.5.1 and seeing if the problem goes away. If it doesn't it may be worth running dtruss on it (or strace on Linux) to narrow down where it comes from. If you're unfamiliar with it, here's a nice tutorial.

Collapse
hoelzro profile image
Rob Hoelz

I don't have a ton of experience with Ruby, but I've seen this when using rbenv when a library that Ruby was compiled against a library that has been updated. I would try building a fresh rbenv installation of the same Ruby version and see if that fixes the issue; if not feel free to ping me and I'll help you work through it!

Collapse
rhymes profile image
rhymes

The first thing I would try is to see if the issue is still there on Ruby 2.5.1.

Does it happen only with rspec?

Collapse
andy profile image
Andy Zhao (he/him) Author

Yeah pretty much. I never hit it when running rails server or any other Ruby/Rails commands.

Collapse
tamouse profile image
Tamara Temple

I'm seeing a segfault when I try to bisect a series of tests. I'm already running 2.5.1. Running rspec without the bisect works fine.

Collapse
andy profile image
Andy Zhao (he/him) Author

Hmm that's interesting. What's bisecting? Is that the default that comes with running the rspec command? I'm using a bin command that's runs plain rspec, and now that I think about it I haven't tried running the entire test suite in guard.

Edit: No luck in guard, and judging from our bin/rspec command, doesn't seem like we are bisecting either. The investigation continues...

Collapse
tamouse profile image
Tamara Temple

rspec bisect is so very cool. let's say running in CI, you had some failures, and you want to find out if they happen to be order-dependent, or if there's a root of something failing. You pass the test command, with the seed the tests were run with and the --bisect command, and rspec will find the minimal set of tests that need to run in order to reproduce the set of failures; hopefully winnowing down where the actual failure is coming from! Definitely a useful part of the rspec toolbelt

Collapse
andy profile image
Andy Zhao (he/him) Author

Thanks, seems like upgrading is the easiest and best option.