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

Concurrent checkouts leads to incorrect value for product stock #203

Closed
TWarszawski opened this Issue Aug 17, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@TWarszawski
Copy link

TWarszawski commented Aug 17, 2016

When two customers check out concurrently for the same product, only one of the checkouts may be reflected in the final value for product stock.

Steps to reproduce:

  1. Start demo site, create two customers, create/pick test product.
  2. Both customers add the product their cart and Perform a checkout concurrently, making sure both customers finish checkout (click the Submit Order button) as close to the same time as possible.

We have reproduced this behavior on a single machine, by performing the above steps with one customer in one browser window and another customer in a second browser window with a short communication delay (100 ms) between the database and application. If connecting to the database using unix sockets, the following script can act as a proxy that delays packets:
https://gist.github.com/TWarszawski/a0d8dd8aea9eb5b774d64c9f826de6db

Expected Result:
The final product stock value is original - 2.

Actual Result:
The final product stock value is original - 1, or the application crashes. See log:
stacktrace.txt

diefenbach added a commit that referenced this issue Feb 23, 2017

Use F() expressions to update stock amount
This is the default Django way to handle race conditions on counters.

This should fix issue #203. Untested as I’m not using MySQL.
@diefenbach

This comment has been minimized.

Copy link
Owner

diefenbach commented Feb 23, 2017

Should be fixed in dev. Please reopen if it's not the case.

5c53fc8

@diefenbach diefenbach closed this Feb 23, 2017

diefenbach added a commit that referenced this issue Mar 2, 2017

Use F() expressions to update stock amount
This is the default Django way to handle race conditions on counters.

This should fix issue #203. Untested as I’m not using MySQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment