Any ideas why Rails hangs intermittently?

Hello,

I’m stumped. I have a Rails app that seemingly hangs at random times.
I am the only user, but my non-optimized application loads a lot of
objects (around a thousand) for some report views. Sometimes
everything works well. However, if I logout, login, and run the
report again, I can usually get the app to hang. I may need to repeat
this procedure a couple of times before it hangs again.

By hanging, I mean that the development.log file stops scrolling (I
have a terminal window tailing it), and my browser waits
indefinitely. The weirdest part is that when I hit control-c to
interrupt Mongrel, Mongrel announces that it may take up to 60
seconds to shut down, and a few seconds later, a huge number of
queries are executed. It seems like Rails is hanging on something,
and the shutdown command wakes up the thread which starts querying
the database again. It often hangs while trying to query Join Table
Columns, but not exclusively.

My schema has 3 main tables, and 2 intermediate join tables. A habtm
B and B habtm C.

I’ve ruled out any kind of resource contention on my database. For
oracle people, v$lock shows nothing for my sid and v$locked_object is
empty.

I thought that maybe adding a pause so ruby could catch up on its
garbage collecting might help, so I added a Kernel.sleep 1 every 100
or so queries. This made it seem like it worked better, but I could
still get it to fail, so I might be imagining any improvement.

I have plenty of free RAM in my machine, and when the Mongrel process
hangs, it uses anywhere from 35-41MB. The amount of CPU usage while
hung is very small.

I am not opening any files on the filesystem.

I am not rotating my log files.

I’m using Rails 1.2.3, os Mac OS X 10.4.9, in development mode,
Mongrel 1.0.1 and Oracle 10.2. I’m using oracle instant client 10.1
and ruby-oci8-1.0.0-rc2.

I can get the same behavior when I run the app through webrick.

Does anyone have any ideas why Rails hangs intermittently?

Thanks,

-Anthony

I found out the bug. I was storing an ActiveRecord model object in
the session and didn’t know that I had to add a model declaration at
the top of my controller to force Rails to preload the class
definition so that the object could be deserialized.

One would expect there to be some kind of helpful error message in
the log, instead of just hanging. Hope this info helps someone out in
the future!

-Anthony