This project is archived and is in readonly mode.

#495 ✓stale
skibumsworld

Racing Inside ActiveSupport::Dependencies

Reported by skibumsworld | June 27th, 2008 @ 02:11 AM | in 2.1.3

I'm working on a project that uses mongrel handlers to service requests. We use ActiveRecord but not ActionController. We've been seeing weird errors which look like:

#<LoadError: Expected ./my_model.rb to define MyModel>

the file does define the class but an exception is thrown. After some digging we found that the problem is in dependencies.rb in the require_or_load method.

If a thread is interrupted right after:

loaded << expanded

then any other threads that attempt to load the same file will get the error above, because the file hasn't been loaded yet even though it's name already appears in the loaded list.

I've included a test to reproduce this. The test only works against the development version of rails. If you want you can run it against other version but you will need to change the way Dependencies module is declared since it didn't used to be inside the ActiveSupport module.

I'm working on a patch right now, but any suggestions on how to fix this issue are more then welcome.

One last thing. When running the test please don't forget to change the first require to point at the correct location for activerecord.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages