nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.3k stars 5.32k forks source link

Concurrent checkouts can lead to negative stock. #4184

Closed sinaislam closed 4 years ago

sinaislam commented 4 years ago

nopCommerce version: Maybe for all versions. Tested for nopCommerce 4.0,4.1 and 4.2.

Steps to reproduce the problem: When two customers check out concurrently for the same product and the total quantity being ordered is greater than the quantity available, the stock can become negative.

Start site, create two customers, create/pick test product and allocate some stock. Both customers add the product to their carts such that each cart individually is under (and not equal to) the available stock, but combined they exceed the available stock. Perform a checkout concurrently, making sure both customers finish checkout (click the 'Place Order’ button) as close to the same time as possible. We have reproduced this behavior on a single machine, by performing the above steps by simulating one customer in one browser window and another customer in a second browser window.

Expected result One of the two checkouts fails to complete. Actual result Both checkouts succeed and the quantity for the product is negative in the admin console.

Copied from https://github.com/magento/magento2/issues/6363. But it is happening at nopCommerce also. When special campaigning starts on the site it happens very frequently. It is important to be fixed.

AbuSalehSumon commented 4 years ago

As a store owner, we faced the same issue during several sales campaign - Nop is poor at calculating & updating stock when it comes to serving a large number of concurrent customers who are trying to place an order against the limited stock. We faced over a hundred of overselling aginst total stock of 50 on 25 plus different items.

nopCommerce should bring a solution to this.

arnileibovits commented 4 years ago

Any comments from developers? This is a more general issue with nopCommerce. There does not seem to be any concurrency handling or transactions whatsoever.

AndreiMaz commented 4 years ago

It's just not possible to fix because a payment could be completed on a third-party payment website. So we leave it to store owners to manage such cases

arnileibovits commented 4 years ago

This is just lazyness or downright ignorance. Any self-respecting developer understands how to handle concurrency.

fredericvachon commented 3 years ago

@AndreiMaz, would you know of documented recommendations to manage such cases?

Thank you

jonquickqsense commented 3 years ago

This is just lazyness or downright ignorance. Any self-respecting developer understands how to handle concurrency.

I think there is a need for a FIFO message queue for order placement, any 'place order' request needs to validate the available stock, based on opening stock position and any pending stock allocations on the queue.

saeidmh83 commented 2 years ago

It's just not possible to fix because a payment could be completed on a third-party payment website. So we leave it to store owners to manage such cases

I think the only way to manage this is to reserve stock and order in the booked mode for a limited time (the time required for payment operations). At the end of the time, the status of the order changes to the unpaid, and the stock is returned.