Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart + Ajax #93

Closed
neochief opened this issue Aug 4, 2015 · 2 comments
Closed

Cart + Ajax #93

neochief opened this issue Aug 4, 2015 · 2 comments

Comments

@neochief
Copy link

neochief commented Aug 4, 2015

My application adds/removes item from cart through ajax calls. Plus, there's an ajax call, which returns actual cart contents. I discovered that sometimes, if you fire these call simultaneously, the cart contents could be screwed due to the way Laravel handles session data.

Here's example:

  1. Fire cart/get ajax request.
  2. Fire cart/add ajax request.
  3. The problem can be discovered if first request runs slower than the second.

You would expect that after this the cart will be filled with one item. But it will be empty. Here's why.

  • The cart/get reads empty cart from session, but somehow it's slow, so it takes some time...
    • In the meantime, in parallel thread, cart/add loads session, adds item to the cart, saves session and exits.
  • Cart/get thread is almost done, and it's going to save it's session data before exit. It's session data is empty (since it read session before cart/add launched), so once it's saved the session, the cart will be empty again.

Here's the Laravel thread, which describes this issue: laravel/framework#5416

The possible solution is to keep the actual cart data in database by sessionId key. This way the cart contents won't be overwritten on every request.

@bonucci
Copy link

bonucci commented Aug 8, 2018

Does this issue still persists?

@xscasnya
Copy link

@bonucci - Yes the issue still persists. However as I read through the problem which @neochief posted, it's not a issue with this package but Laravel itself. This issue has been here for a long time and is still present, the latest overview summary I have found is this laravel/framework#30996

The possible solution is to use https://github.com/rairlie/laravel-locking-session but keep in mind that this solution basically makes all your AJAX requests synchronous, which isn't a great solution for modern SPA's as mentioned in the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants