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

Sergio Salvi sergio.lists at salvi.ca
Thu Nov 20 20:16:34 GMT 2008


On Fri, Sep 26, 2008 at 3:49 PM, Daniel Westermann-Clark <dwc at pobox.com> wrote:
> On 2008-08-26 09:47:59 +0200, Tobias Kremer wrote:
>> a) Patch Catalyst::Plugin::Session::Store::DBIC to wrap the flash
>>    functionality in a transaction (of course, this must be
>>    configurable).
>
> I've released a new version which includes this functionality:
>
> 0.07  Wed Sep 24 17:08:34 EDT 2008
>        - Code was silently truncating storage to MySQL, rendering the
>          session unreadable. Patched to check DBIx::Class size from
>          column_info (if available)
>        - Wrap find_or_create calls in a transaction to (hopefully)
>          avoid issues with duplicate flash rows
>

Thanks for the patch, but unfortunately it does not solve the problem
with duplicate flash rows, because just wrapping find_or_create()
inside a txn_do() doesn't make it an atomic operation (because
find_or_create is simply not atomic, as pointed out in this thread).

The biggest problem is that the flash row gets deleted from the
database when flash is empty, so we're always doing insert & delete
and triggering the find_or_create problem.

I have a template to display error messages that is included by almost
every page, and these error messages are stored in flash. So every
request that does *not* have anything in flash and does not add
anything to flash, basically inserts the row (because my template did
something like "FOREACH c.flash.my_error_messages"), leaves the flash
empty and then decides to delete it. Make this happen too quickly and
you're hitting this problem very often (like we were on our
application).

I've modified Session.pm not to delete flash, even when it's empty.
The problem is gone, but it's a temporary hack I did to my local
version of Session.pm.

I still think the final solution (besides finding a way to make
find_or_create() atomic), is to store flash data the session row
(either on the same column of session or on a new, dedicated column).

I could try coming up with a patch + tests for this. Thoughts?

Thanks,
Sergio Salvi



More information about the Catalyst mailing list