I have an application running on dreamhost with fast cgi (FCGI). I have
model, “Member”, that has the following validation:
validates_uniqueness_of :email, :if =>
The :if clause is really not needed because an email address is required
in fact the model also has:
The problem is that I’m getting some non-unique or duplicate email
The volume to the site is relatively low.
The logs indicate things were pretty slow when these duplicates showed
It looks like an initial post took more than 30 seconds, and was
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
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
app did not respond, so the user hit the button a couple more
it be that each post was picked up by a different FCGI process, and that
3 processes did their own independent evaluation of uniqueness, and then
three saved their Member records so that we ended up with 3 non-unique
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
occurs when multiple processes try to write the same email address.
Please help me find the bug in my code. Thanks.