Dreamhost, fastcgi, validates_uniqueness_of.... is not alway

Hey everyone,

I have an application running on dreamhost with fast cgi (FCGI). I have
a
model, “Member”, that has the following validation:

validates_uniqueness_of :email, :if =>
Proc.new{|member| !member.email.blank?}

The :if clause is really not needed because an email address is required
and
in fact the model also has:

validates_presence_of :email

The problem is that I’m getting some non-unique or duplicate email
addresses.

The volume to the site is relatively low.

The logs indicate things were pretty slow when these duplicates showed
up.
It looks like an initial post took more than 30 seconds, and was
repeated at
least 2 more times before any of the 3 completed. They all seemed to
complete at the same time.

As I mentioned the app is running on Dreamhost, so I’m not surprised
that
things are sometimes a little slow – who knows what could have been
happening at that point.

So assuming something external to the app slowed everything down, and
the
app did not respond, so the user hit the button a couple more
times…could
it be that each post was picked up by a different FCGI process, and that
the
3 processes did their own independent evaluation of uniqueness, and then
all
three saved their Member records so that we ended up with 3 non-unique
email
addresses?

I’m using mysql and the tables are all innodb, but I have no constraints
defined. I thought “validates_uniqueness_of” worked. Does it?

I have a unit test that tries to write two Member records with identical
email addresses, and it generates an error as expected. I think the
failure
occurs when multiple processes try to write the same email address.

Please help me find the bug in my code. Thanks.

-Kelly