This project is archived and is in readonly mode.

#3696 ✓invalid
Gravis

Race conditions with cookie session store

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

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.

Comments and changes to this ticket

  • Gravis

    Gravis January 17th, 2010 @ 06:05 PM

    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

  • Gravis

    Gravis January 21st, 2010 @ 09:01 AM

    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.

  • Rizwan Reza

    Rizwan Reza January 21st, 2010 @ 03:52 PM

    • 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!

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages