[BUG] cross-thread violation on rb_gc()

I was recently involved in upgrading a project from Ruby 1.9.2 to 1.9.3. As part of this upgrade we also upgraded several of our gems (including Rails) to the latest versions. Everything went smoothly, but when I tried to run the latest version of the code on my laptop (MacBook Pro) I got the following error:

[BUG] cross-thread violation on rb_gc()

I was using RVM and bundler, so as far as I knew (which isn’t all that far) everything should just work.

I did what every responsible dev would do – I googled the error message. Unfortunately this doesn’t seem to be a very common problem and most of the solutions involved removing and reinstalling the json gem (which didn’t work for me).

I tried quite a few solutions, including nuking all local gems (so gems not installed through bundler) – no luck. I also reinstalled Ruby 1.9.3 – no luck. I even pulled down the project into a different directory and I still got the same error.

In the end the problem was with the RVM gemset. I simply removed and recreated the RVM gemset and this fixed the problem.

rvm gemset delete your_gemset_name

Hopefully this will help someone else with the same problem. Happy coding.