You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Fire cart/get ajax request.
Fire cart/add ajax request.
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.
@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.
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:
You would expect that after this the cart will be filled with one item. But it will be empty. Here's why.
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.
The text was updated successfully, but these errors were encountered: