6

The codebase I'm working on was recently upgraded from Ruby 1.9.2 to Ruby 1.9.3 and from Rails 3.1 to Rails 3.2.2. Since I'm using RVM I simply did rvm install 1.9.3 which I would have expected to be all that was necessary.

When I run

rails s

I get the error

[BUG] cross-thread violation on rb_gc()

I've found a number of links relating to this problem. There is one on StackOverflow, but it doesn't really give an answer. The most promising answer is on the RVM site:

In every case of this I have seen thus far it has always ended up being that a ruby gem/library with C extensions was compiled against a different ruby and/or architecture than the one that is trying to load it. Try uninstalling & reinstalling gems with C extensions that your application uses to hunt this buggar down.

That's fairly helpful, but my Ruby-fu is not strong enough to know which gems have C extensions and which ones I should try to re-install. Quite a few of the other links on the topic seem to suggest that the json gem is at fault, so I tried following the suggested solution.

gem uninstall json 
gem install --platform=ruby

This didn't really change anything for me—I still get the exact same error when trying to start the Rails environment.

How do I track down this problem?

If it helps, here is the output from gem list:

actionmailer (3.2.2)
actionpack (3.2.2)
activemodel (3.2.2)
activerecord (3.2.2)
activeresource (3.2.2)
activesupport (3.2.2)
addressable (2.2.7)
akami (1.0.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bson (1.6.1)
bson_ext (1.6.1)
builder (3.0.0)
bundler (1.1.3, 1.0.21)
capybara (1.1.2)
carmen (0.2.13)
childprocess (0.3.1)
ci_reporter (1.7.0)
coderay (1.0.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
commonjs (0.2.5)
cucumber (1.1.9)
cucumber-rails (1.3.0)
database_cleaner (0.7.2)
devise (2.0.4)
diff-lcs (1.1.3)
ejs (1.0.0)
email_spec (1.2.1)
engineyard (1.4.28)
engineyard-serverside-adapter (1.6.3)
erubis (2.7.0)
escape (0.0.4)
execjs (1.3.0)
factory_girl (3.0.0)
factory_girl_rails (3.0.0)
faker (1.0.1)
fakeweb (1.3.0)
ffi (1.0.11)
gherkin (2.9.3)
gyoku (0.4.4)
haml (3.1.4)
haml-rails (0.3.4)
hash-deep-merge (0.1.1)
highline (1.6.11)
hike (1.2.1)
httpi (0.9.6)
i18n (0.6.0)
jasmine (1.1.2)
jasmine-core (1.1.0)
jasminerice (0.0.8)
journey (1.0.3)
jquery-rails (2.0.1)
json (1.6.6)
json_pure (1.6.6)
kaminari (0.13.0)
kgio (2.7.4)
launchy (2.0.5)
less (2.1.0)
less-rails (2.2.0)
libv8 (3.3.10.4 x86_64-darwin-11)
log4r (1.1.10)
mail (2.4.4)
metaclass (0.0.1)
method_source (0.7.1)
mime-types (1.18)
mocha (0.10.5)
mongo (1.6.1)
mongoid (2.4.7)
mongoid-rspec (1.4.4)
multi_json (1.2.0)
net-ssh (2.2.2)
newrelic_rpm (3.3.3)
nokogiri (1.5.2)
nori (1.1.0)
open4 (1.3.0)
orm_adapter (0.0.7)
polyglot (0.3.3)
pr_geohash (1.0.0)
pry (0.9.8.4)
pry-highlight (0.0.1)
pry_debug (0.0.1)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.2)
rails-footnotes (3.7.6)
railties (3.2.2)
raindrops (0.8.0)
rake (0.9.2.2)
rdoc (3.12)
recursive-open-struct (0.2.1)
rest-client (1.6.7)
rpm_contrib (2.1.8)
rsolr (1.0.7)
rspec (2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.0)
rspec-mocks (2.9.0)
rspec-rails (2.9.0)
rubyzip (0.9.6.1)
sass (3.1.15)
sass-rails (3.2.5)
savon (0.9.9)
selenium-webdriver (2.20.0)
settings-tree (0.2.1)
simplecov (0.6.1)
simplecov-html (0.5.3)
simplecov-rcov (0.2.3)
slop (2.4.4)
spine-rails (0.1.0)
spork (1.0.0rc2)
sprockets (2.1.2)
sunspot (1.3.1)
sunspot_mongoid (0.4.1)
sunspot_rails (1.3.1)
sunspot_solr (1.3.1)
term-ansicolor (1.0.7)
therubyracer (0.10.1)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
twitter-bootstrap-rails (2.0.6)
tzinfo (0.3.32)
uglifier (1.2.4)
unicorn (4.2.1)
warden (1.1.1)
wasabi (2.1.0)
xpath (0.1.4)
Community
  • 1
  • 1
Jaco Pretorius
  • 24,380
  • 11
  • 62
  • 94
  • i know the stacktrace from ruby is enormous, but can you find the place it crashed in and post the relevant part? I've encountered a similar crash in ruby and it was a gem that I was able to revert to another version and avoid the crash. The answer may be in the stacktrace. – edk750 Apr 21 '12 at 06:36
  • It turns out my problem was actually with the rvm gemset. I simply needed to nuke the gemset and recreate it - this fixed the problem. – Jaco Pretorius Apr 23 '12 at 21:15

5 Answers5

6

Here are various approaches you can try.

cleanup

To clean up old versions of your gems:

gem cleanup --dryrun

json

To temporarily see if the json gem is the issue, switch from json (native) to json (pure ruby) and change your Gemfile:

gem install json_pure 

native gems

Your gem list has a few that pop out for me as native:

  • bcrypt
  • bson
  • erubis
  • ffi (enables lots of native connections)
  • gherkin
  • kgio
  • less
  • nokogiri
  • raindrops
  • therubyracer (many unpredictable issues IMHO)
  • unicorn

ffi

Your gem ffi is especially interesting -- do you happen to know what you're doing with it?

The ffi enables Ruby code to call native code, for example if some part of your Ruby app needs to connect to native libraries.

When you're diagnosing your issue, I'd look at this gem first.

makefiles

To find any of your gems that have Makefile files, which is a good indicator that they have native code:

find / | grep "/ruby/gems/" | grep Makefile

To find all your gems so you can delete them:

find / | grep "/ruby/gems/"

nuke RVM

To nuke RVM or its pieces, you can use rvm uninstall, rvm implode, or this script which nukes RVM and finds any lingering pieces:

https://raw.github.com/SixArm/sixarm_unix_shell_scripts/master/rvm-uninstall-danger

try rbenv + bundler

I changed from using rvm to using rbenv + bundler and it's working great for me.

The rbenv tool is a direct competitor to rvm for managing Ruby versions: https://github.com/sstephenson/rbenv

Bundler is a great way to manage gemsets and gem dependencies: http://gembundler.com/

brew

If you're on a Mac and using MacPorts, to change to Homebrew:

Link

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • This didn't really fix the problem, but I guess nuking RVM would have also fixed it (since my problem was actually with the gemset being corruct) – Jaco Pretorius Apr 23 '12 at 21:16
  • Trying rbenv + rbenv-gemset + rbenv-installer last year, it was seriously broken and the community was not behind it. https://github.com/jamis/rbenv-gemset/issues/17 –  Apr 24 '12 at 03:10
  • 1
    @Barry You're right about rbenv-gemset -- it's a plugin to rbenv, and don't use it IMHO; instead, use rbenv + bundler. Bundler is the best thing to come along for managing gemsets and it works great with rbenv, Rails, and even building standalone ruby projects. – joelparkerhenderson Apr 24 '12 at 15:13
  • @joelparkerhenderson Bundler is badass. Used in production along with GemFury to roll up an enterprise Ruby (server) app for Mac, Windows and Linux. –  Apr 25 '12 at 20:44
4
  1. Uninstall all verions of json gems by running: gem uninstall json

  2. Then run: gem install json --platform=ruby

  3. Run bundle again:bundle install

Johnny Woo
  • 1,036
  • 1
  • 8
  • 3
1

You should try nuking all of your gems and reinstall them for your app using the bundle command.

Quoting the RVM documentation for this error:

Try uninstalling & reinstalling gems with C extensions that your application uses to hunt this buggar down.

The command to remove gems with RVM is simply:

rvm uninstall
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
hagope
  • 5,523
  • 7
  • 38
  • 52
  • I tried that, still getting the same error - even after removing ALL local gems. Even cloned my repository and started from scratch - still the same problem. – Jaco Pretorius Apr 19 '12 at 18:16
0

A clean reinstall of RVM latest is the best option.

rvm implode

rm -rf ~/.rvm

curl -L get.rvm.io | bash -s stable

0

Before going the clean ruby/rvm install route you should check if you have removed ruby 1.8.7 (which is installed by default on most distributions). I believe this was interfering with some of my gems compiled with 1.9.2 (I think it was one of the native ones). I removed 1.8.7 completely using apt-get then I made a new rvm profile (by changing the profile name in .rvmrc) and then ran bundle install to refresh all the gems completely.

RonanOD
  • 876
  • 1
  • 9
  • 19