Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX Lion and Ruby - [FATAL] failed to allocate memory

Tags:

ruby

osx-lion

I have serious problem with Ruby and OSX Lion - whenever I try to start Rails or even a rake tool I am getting this error:

[FATAL] failed to allocate memory

I tried recompilling ruby in different versions (1.9.2-p180, 1.9.2-p290, 1.9.2-head) and its always the same.

However I noticed that I can remove some gems and then "rake" tool will work and only 'rails s' will die with that error. It seems like there is in fact not enough memory for this amount of gems I am using, but again this seems very weird - it works perfectly fine on Snow Leopard and even at my company on mac mini with Lion - the only difference is that the mini is upgraded Snow Leopard -> Lion, whilst on my iMac its a clean Lion installation.

Any ideas? Is there a setting of some kind to increase memory on OSX/Lion?

like image 429
Kamil Durski Avatar asked Aug 14 '11 09:08

Kamil Durski


3 Answers

It took me some time to figure it out but here is the solution:

This problem was caused by mysql2 gem, when I switched to ruby-mysql it all started working again (remember to change adapter from mysql2 to mysql in your database.yml!)

So I started thinking about differences between mac mini and iMac. Basically the mini is running Lion upgraded from Snow Leopard, which is upgraded Leopard and it has good, old Mac Ports for mysql and pgsql servers. So when gem is compiled its using port libraries.

On the other hand the iMac with fresh Lion installation has Zend Server package (apache + php + mysql binaries) and a Homebrew package 'mysql-connector-c' that has libraries needed to compile gem.

All in all it seems as if ports version of mysql works correctly whereas Homewbrew connector does not (its leaking some memory?).

Hope this helps.

like image 51
Kamil Durski Avatar answered Dec 07 '22 18:12

Kamil Durski


I uninstalled mysql2

$ gem uninstall mysql2

And reinstalled via bundler

$ bundle

And I'm able to rails s once again

like image 24
Joe Sak Avatar answered Dec 07 '22 19:12

Joe Sak


I had a conflicting package mysql-connector-c from homebrew installed. mysql2 used the dylib from this package and not from the mysql install. Removing the homebrew package yielded another problem, which could be solved by adding

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"

to my environment.

like image 24
urandom Avatar answered Dec 07 '22 18:12

urandom