Confused classes

Warren Konkel warren.konkel at
Sat Feb 6 07:33:13 EST 2010

I switched from mod_passenger to unicorn on a fairly high traffic site
and ran into a strange problem that forced me to move back to
mod_passenger... it seems as if classes would sometimes get mixed up
with each other.  If I had two Rails models:

  class Foo < ActiveRecord::Base;  end
  class Bar < ActiveRecord::Base;  end

Normally Foo.inspect and Bar.inspect would return:

  Foo(field1: integer, field2: integer)
  Bar(field3: integer, field4: integer)

When things were "broken" within a process, sometimes I would see:

   Foo(field3: integer, field4: integer)    <--- note field3/field4
actually belong to Bar, not Foo

And because of that, wacky errors would appear in my logs like:

   Foo.find_by_field1(12345) --> not a method
   Foo.create(:field1 => 12345)  --> column not found

I also noticed the problem with field serializing in ActiveRecord... given:

  class Boz < ActiveRecord::Base
    serialize :some_data

When processes were working correctly,  Boz.find(1).some_data would
return an actual object (like a Hash).  When things were broken, the
raw serialized string from the database would be returned... almost as
if the Boz class "forgot" that it's supposed to deserialize

Could it be that class attributes are somehow being co-mingled when
unicorn is starting up under high concurrency?  Perhaps a mutex is
missing somewhere?

More information about the mongrel-unicorn mailing list