Segmentation fault with Rails after upgrading to OS Sierra, possibly related to sqlite3 gem
Asked Answered
G

7

24

After upgrading to OSX Sierra I am having an issue with random segmentation faults. It most commonly occurs when running rails test and I believe it is due to the sqlite3_adapter.

My present work around is to simply quit terminal and restart it. This works for about 1 or 2 rails test and by the third one I am almost guaranteed to get another segmentation fault.

Is anybody else having an issue with this or find a better workaround?

$ rails t
Running via Spring preloader in process 13817
/Users/USER/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27: [BUG] Segmentation fault at 0x00000000000110
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]

Edit:

After digging into the sqlite3_adapter.rb, I see that the line causing the segmentation fault is the creation of a new SQlite3 database.

db = SQLite3::Database.new(
    config[:database].to_s,
    :results_as_hash => true
)

Edit 2:

Rather than quitting and restarting terminal, I have found that running:

spring stop

stops the problem temporarily. Not a solution, but a better work around.

Edit 3:

This appears to be a problem with Apple's supplied libsqlite3 not being fork safe. More info can be found here:

https://github.com/sparklemotion/sqlite3-ruby/issues/195

For now, I have created an alias at the bottom of my ~/.bashrc file:

alias ss='spring stop'

When the problem occurs, I can now type:

ss

and then rerun the test.

Gusti answered 2/10, 2016 at 0:15 Comment(0)
G
8

Looks like a patch has been issued! The patch will look for sqlite3 in your brew folder instead of using Apple's supplied version by default. Simply run:

bundle update

to get the latest version of sqlite3-ruby and if you don't already have sqlite3 installed in your homebrew directory, run:

brew install sqlite3
Gusti answered 9/10, 2016 at 20:19 Comment(4)
this worked for me. If you get a "This formula is keg-only, which means it was not symlinked into /usr/local" message, I ignored it without having an issue.Montgolfier
Just a quick note to say this is the exact sequence of commands that worked for me: brew install sqlite3; gem uninstall sqlite3; bundle update.Keitel
I can't get this to work for me. I have run this several times as well as gem pristine sqlite3 and still nothing works. I am running ruby 2.3.3. Is there anything else I can do?Balaklava
Do you have homebrew installed? What do you see when you run brew listGusti
S
4

I had the same problem when upgrading to Sierra. A simple bundle update will do the trick! Hope this helps.

Syringa answered 2/10, 2016 at 15:21 Comment(3)
This worked temporarily but it looks like the problem is back. :(Gusti
@Gusti Same thing happened here.Cannibal
It helped me, macOS SierraQuill
G
2

Try rebuilding the sqlite3 gem. It has native extensions, and recompiling them in the Sierra environment may fix the issue.

Run:

gem pristine sqlite3

Which should give output like:

Restoring gems to pristine condition...
Building native extensions.  This could take a while...
Restored sqlite3-1.3.10
Building native extensions.  This could take a while...
Restored sqlite3-1.3.11
Galina answered 2/10, 2016 at 0:59 Comment(2)
That didn't do it. I tried uninstalling and reinstalling the sqlite3 gem as well. No luck.Gusti
This was the last step needed after installing sqlite3 from Homebrew.Misunderstood
G
2

I've noticed that I get a segfault as well, when trying to run rails console --sandbox specifically. I found this other question that seemed to fix this issue; specifically running

xcode-select --install

seemed to resolve it. This is by no means scientifically proven yet, however I am now able to run a rails console and all tests without a ruby segment fault.

Germiston answered 6/10, 2016 at 4:42 Comment(1)
Tried that and I'm just getting they are already installed. Thanks for the suggestion!Gusti
D
0

Same problem w/Sierra. None of the stuff on this page worked for me, i.e. gem pristine sqlite3, xcode-select --install, sqlite3; gem uninstall sqlite3; bundle update. I eventually completely uninstalled the Ruby version with rbenv uninstall 2.3.1, then reinstalled it. This worked. I have no idea why.

Deserve answered 1/12, 2016 at 2:30 Comment(0)
A
0

I faced the same issue, I upgraded sqlite3 gem to 1.3.12 and it helped

Ardys answered 3/12, 2016 at 23:29 Comment(1)
after editing gem file, it is required to run bundle installArdys
H
0

All the previous solutions didn't worked so I've fixed this way:

gem uninstall sqlite3

brew install sqlite3

gem install sqlite3 -- --with-sqlite3-include=/usr/local/Cellar/sqlite/3.15.2/include --with-sqlite3-lib=/usr/local/Cellar/sqlite/3.15.2/lib

(Check the version you have in Cellar)

This is a temporary fix and probably if update the bundle it will stop working and you will do it again but al least I can work on my machine

Hurtful answered 12/12, 2016 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.