[Catalyst] Duplicate entries with C::P::Session::Store::DBIC and MySQL - new findings

Tobias Kremer list at funkreich.de
Tue Aug 26 08:47:59 BST 2008

Hey guys,

just wanted to inform you that switching from MyISAM to InnoDB for the session
table does NOT solve the "duplicate entry" problem when using flash() :(

I really can't believe that me and 3 or 4 others are the only people
experiencing this problem! We're getting close to 400 of those errors over a
weekend with moderate traffic (2-3 million page impressions). The problem with
this error is that the user receives a 500 error page when in reality nothing
really bad happened (it's just a flash message that couldn't get inserted, you

Now AFAICT we have these solutions:

a) Patch Catalyst::Plugin::Session::Store::DBIC to wrap the flash
   functionality in a transaction (of course, this must be configurable).
     - Easy to implement
     - Most sensible solution.
     - Slight performance overhead?
     - Doesn't solve the problem for non-transactional databases

b) Patch DBIx::Class's find_or_create() method and reverse its order
   (insert first, check for duplicate, then select).
     - Not that easy to implement because every database returns
       a different error to signal a unique key constraint violation.
     - It's quite possible that this doesn't really solve the problem
       but just changes the error. If the row is deleted between insert
       and select (this race condition still exists), find_or_create()
       will return nothing and AFAICT C::P::Session::Store::DBIC's
       flash() method expects a working row object.
     - find_or_create() will be faster everywhere in many cases.

Anything else? What do you propose?

There's a hint in the POD about a "soon to be developed locking solution" which
should get rid of this race condition. Please note, that this is ONLY happening
with the flash part - my sessions work 100% accurate all the time!

We really should sort this thing out because it's bugging me for ages. Again, I
can't believe that I'm almost the only person with this problem.

If we are unable to fix it, I'll remove the flash() stuff from my code and tell
everyone that it's b0rken ;-)


More information about the Catalyst mailing list