Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Race conditions with cookie session store

#3696

Hello,

I'm having a problem avec race conditions with the cookie session store. I use the user session (=cookie) to store items of his/her cart until checkout.
items are adding through a very simple ajax action (cart_items/create). I have noticed that even though all items seem to be added the cart (they are displayed as a cart item, result from the create.rjs view), the cart total is sometimes wrong. If I reload the page, I understand the cart total is indeed OK, and some items disappear from the cart.
After logging a lot of thing related to my session cart, it appears I'm running into this problem :
http://www.paulbutcher.com/2007/05/race-conditions-in-rails-session...

Some are saying cookie store should have solved the problem, I must say it has not. The race conditions problem occurs between the 2nd and 3rd click. 2nd click will add the item to cart, and display a line in my cart. 3rd click in the same time has copied the session before the 2nd click actually added the item, so after 3rd click, I have 3 items displayed, and a total for 2 items (1st and 3rd).

Unfortunately, I don't see any solution for this, but at least a ticket is created as a reminder.

Reported by Gravis · January 15th, 2010 @ 10:47 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Gravis
    Gravis

    Notice : this issue can be solved using an ajax queue apparently (funny to have an asynchronous action synchronized :) )
    http://github.com/nakajima/jquery-ajax-queue

    January 17th, 2010 @ 06:05 PM

  2. Gravis
    Gravis

    Using the ":type => :synchronous" option of link_to_remove solved my problem, but the browser has to wait until the end of the ajax action. Not perfect, but at least no more issues with false total.

    January 21st, 2010 @ 09:01 AM

  3. Rizwan Reza
    Rizwan Reza
    • State changed from new to invalid

    Gravis, I'm updating this ticket as invalid, as you seem to have already found the solution. Though if you think I am wrong, please update the ticket with a failing test so I can dig in. Thanks!

    January 21st, 2010 @ 03:52 PM