Strange class loading problem in production environment

I have an extremely strange bug that I’ve only been able to reproduce
in the context of active-messaging. But, stepping through the code,
the problem appears to be at the level of dependencies.rb, so I will
post also here to see if anyone has any insight to this problem.Any
help or ideas on tackling this would be greatly appreciated.

I’m using Rails 2.1. Here’s the problem:

Assume you have a file lib/foo/bar.rb, defined:

module Foo
class Bar
end
end

And that you have an A13g processor that references this class, like:

class MyProcessor < ApplicationProcessor
subscribes_to :whatever
def on_message(message)
Foo::Bar
end
end

If I run a message through to the poller, this processor correctly
autoloads the class. On subsequent tries, I get an exception:

LoadError raised: Expected c:/app_root/lib/foo/bar.rb to define
Foo::Bar

  • I’ve only found this odd behavior when running in production mode.
    Development mode is just fine.
  • Also, the file has to be within a subfolder on the load path (i.e. a
    subdirectory of lib). ‘lib/bar.rb’ loads each time just fine.
  • I’ve produced it on both Solaris and Windows platforms.

I have tried debugging through the source. Here is all I can gather:

Both first and second invocation get to gems/custom_require.rb:27. At
that point, stepping through the source code the first time takes me
to the line ‘module Foo’ in lib/foo/bar.rb.

The second time around, a step returns immediately, not going into
lib/
foo/bar.rb. Then, a few lines later, the exception is triggered when
the interpreter cannot find the class.

Has anyone encountered this sort of thing? Any idea what this could
be?

What is throwing me is that stepping through the source code, there is
no difference in the code paths taken, just a difference in what
happens when I get to gems/custom_require.rb:27