# Strange class loading problem in production environment

**URL:** <https://www.ruby-forum.com/t/strange-class-loading-problem-in-production-environment/145381>\
**Category:** Rails\
**Created:** [August 8, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/strange-class-loading-problem-in-production-environment/145381 "2008-08-08T16:28:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara\_vartanian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@ara\_vartanian](https://www.ruby-forum.com/u/ara_vartanian)\
**Post date:** [August 8, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/strange-class-loading-problem-in-production-environment/145381/1 "2008-08-08T16:28:14Z")

</div>

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
