The Problem:

When I ran:

> rails generate rspec:install

or

> rails generate cucumber:install

I got:

[BUG] cross-thread violation on rb_gc()
(null)

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

The Solution:

I found this post in the RubyInstaller google group where Luis Lavena had worked with someone else seeing the same issue, and he recognized it as a problem with the json gem version 1.4.6 x86-mingw32 not having binaries for Ruby 1.9.

His recommended fix, that worked for me, is to run:

> gem uninstall json

Then download and install DevKit for the Ruby installation I was using (I’m using pik and was trying to set up a new environment, see the details below)

Then run:

> gem install json --platform=ruby

And then the rails generate rspec:install and rails generate cucumber:install commands worked as expected.

Please comment if this post helped you with the same issue, or if you know how to fix this issue so that it won’t bite others in the future. I’m still a beginning Rubyist (I’ve gotten to a point where I’m starting to know how much I don’t know), and I’m definitely interested in working on this and other problems (which was my original intention of this evening!!!) but I don’t know exactly how to go about doing such things yet, in many cases.

More details:

I’m using pik, the Windows alternative to rvm. My overall goal was to create a new, clean pik environment in which I could create a new rails app using a clean gemset.

So I used the RubyInstaller (thank you again, Luis!) to install Ruby 1.9.2, then I added it to pik and switched to it.

Then I started installing– rails 3.0.3 and cucumber 0.9.4 (the gem I’m interested in reproducing a bug with/patching).

At that point I switched to following The RSpec Book starting on page 286 (of printing 1) which has you do:

> rails new <my-app>
> cd <my-app>

Modify your Gemfile to be:

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'

group :development, :test do
gem 'rspec-rails', ">=2.0.0"
gem 'cucumber-rails', ">=0.3.2"
gem 'webrat', ">= 0.7.2"
end

Then run:

> bundle install

And then finally:

> rails generate rspec:install

And that is how I got to the cross-thread violation on rb_gc(). Phew.

How I got to the solution:

Google searches for:

  • rails generate rspec install bug cross-thread violation
  • "cross-thread violation on rb_gc"
  • pik ruby windows cross-thread violation rb_gc
  • +pik +ruby +windows +cross-thread +violation +rb_gc (yes, google, i really want ALL these terms to be in the pages you give me... what is this, 1997? That's another post...)
  • site:ruby-forum.com "cross-thread violation on rb_gc"
  • bug cross-thread violation dll (i had seen a dll having to do with 1.8 being referenced in the details of the crash as reported by windows)
  • bug cross-thread violation rb_gc dll

Stack overflow searches for:

  • [ruby] [cucumber] cross-thread violation
  • [cucumber] cross-thread violation
  • [rspec] cross-thread violation

I also looked at the issue trackers for pik and a lot of posts on the Ruby Forum.

I have now learned that the RubyInstaller google group is a good place to start looking for windows+ruby related issues.