Are there any claims as to whether Dependencies is thread safe? I was
working on an odd startup problem one of our scripts has and it turns
out that there seems to be a race condition:
2 threads spawn
Thread 1 tries to reference Foo, hits const_missing
Thread 2 tries to reference Foo, hits const_missing
Thread 1 enters require_or_load (in dependencies.rb) and adds foo.rb
to the loaded set
Thread 2 performs the test on line 247 (if file_path && !
loaded.include?(File.expand_path(file_path))) which fails because
loaded does now contain foo.rb
Thread 1 completes loading of foo.rb, Object.const_defined?(:Foo) now
returns true
Thread 2 hits line 253:
elsif (parent = from_mod.parent) && parent != from_mod &&
! from_mod.parents.any? { |p| p.const_defined?(const_name) }
which is also false since either from_mod is Object (in which case
parent == from_mod) or from_mod.parents contains Object in which case
the second part of the test
Thread 2 then raises name_error.
I've added some appropriately placed sleep statements into
dependencies.rb to make this happen systematically rather than it just
being blind luck. In my particular case we can probably work around
this by explicitly requiring stuff, but this may be of interest to
people thinking about thread safety in rails.
Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---