Skip to content

Missing paid orders and lock wait timeouts in Guest Checkout #25862

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

Closed
IvanChepurnyi opened this issue Nov 30, 2019 · 46 comments
Closed

Missing paid orders and lock wait timeouts in Guest Checkout #25862

IvanChepurnyi opened this issue Nov 30, 2019 · 46 comments
Labels
CD Issue recommended for the contribution day Component: Checkout Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Triage: Performance

Comments

@IvanChepurnyi
Copy link
Contributor

IvanChepurnyi commented Nov 30, 2019

Update on Jul 28 2020
The issue was not completely fixed in internal Jira tickets MC-29335 and MC-29206.

That solution looks like not completely fixes a problem, as sales rule usage update still potentially causes deadlock under high load when a lot of concurrent orders are placed at the same time. The only way to fix this problem is by introducing the append-only event log of sales rule counter adjustment log and using cronjob to update sales rule table.

#25862 (comment)
#25862 (comment)

During peak sales hour, one of my customers lost 400+ Magento orders but had charged credit card transactions at the PSP.

At first, I thought PSP implementation was a reason for missing orders, but after the investigation, it turned out this a result of a pull request being merged 2 years ago in Guest Place Order API endpoint of Magento related to this issue #6363.

That change added beginTransaction() and commit() around the whole place order process involving payment API calls and multi-entity save process ignoring that it results in lock contention on database level for an update of the same row in the same table (sales_rule). Although intentions were good (implementation to fix stock deduction issues), but it introduced huge performance bottleneck and rollbacks complete order history for paid and valid orders if wait-lock happens during the ordering process.

Preconditions (*)

  1. Magento 2.2.4+ or Magento 2.3.0+
  2. Enabled Guest Checkout
  3. Site-wide sales rule like "Free shipping above x amount"

Steps to reproduce (*)

  1. Stress test system with concurrent guest orders involving API payment PSP

Expected result (*)

  1. All paid payment transactions are saved to the database and visible in the admin panel

Actual result (*)

  1. A small fraction of orders is saved in the database while the majority of orders lost because of lock wait timeout.

Workaround

If you are using MSI it is possible to completely remove transactions and make it work in the same way as for logged-in user checkouts. Here is a patch that can be applied for "magento/module-checkout":

Index: Model/GuestPaymentInformationManagement.php
<+>UTF-8
===================================================================
--- Model/GuestPaymentInformationManagement.php	(date 1575083782000)
+++ Model/GuestPaymentInformationManagement.php	(date 1575083782000)
@@ -98,33 +98,20 @@
         \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
         \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
     ) {
-        $salesConnection = $this->connectionPool->getConnection('sales');
-        $checkoutConnection = $this->connectionPool->getConnection('checkout');
-        $salesConnection->beginTransaction();
-        $checkoutConnection->beginTransaction();
-
-        try {
-            $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
-            try {
-                $orderId = $this->cartManagement->placeOrder($cartId);
-            } catch (\Magento\Framework\Exception\LocalizedException $e) {
-                throw new CouldNotSaveException(
-                    __($e->getMessage()),
-                    $e
-                );
-            } catch (\Exception $e) {
-                $this->getLogger()->critical($e);
-                throw new CouldNotSaveException(
+        $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
+        try {
+            $orderId = $this->cartManagement->placeOrder($cartId);
+        } catch (\Magento\Framework\Exception\LocalizedException $e) {
+            throw new CouldNotSaveException(
+                __($e->getMessage()),
+                $e
+            );
+        } catch (\Exception $e) {
+            $this->getLogger()->critical($e);
+            throw new CouldNotSaveException(
                     __('An error occurred on the server. Please try to place the order again.'),
-                    $e
-                );
-            }
-            $salesConnection->commit();
-            $checkoutConnection->commit();
-        } catch (\Exception $e) {
-            $salesConnection->rollBack();
-            $checkoutConnection->rollBack();
-            throw $e;
+                $e
+            );
         }

         return $orderId;

@m2-assistant
Copy link

m2-assistant bot commented Nov 30, 2019

Hi @IvanChepurnyi. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@IvanChepurnyi do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Nov 30, 2019
@rhoerr
Copy link

rhoerr commented Dec 2, 2019

This same code also wreaks havoc on error handling, and the ability to handle errors from code when they do occur.

Related issue: #18752 (comment)

@engcom-Charlie engcom-Charlie self-assigned this Dec 3, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 3, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Charlie engcom-Charlie added Component: Checkout Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Dec 3, 2019
@ghost ghost unassigned engcom-Charlie Dec 3, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-29335 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Dec 3, 2019
@PascalBrouwers
Copy link
Contributor

Interested if this will also fix my issues with ghost orders who have an order id in PSP

@sdzhepa sdzhepa self-assigned this Dec 5, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 5, 2019

Hi @sdzhepa. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@sdzhepa
Copy link
Contributor

sdzhepa commented Dec 5, 2019

Hello @IvanChepurnyi @PascalBrouwers @rhoerr

The internal Magento team is working on this issue right now.
Fix is almost done in the scope of internal Jira tickets MC-29335 and MC-29206.
Currently, all development work is done and its on the QA stage.

I will keep updating this Issue with commits as soon as changes will be pushed to the public magento/magento2 repo

@convenient
Copy link
Contributor

Very interesting. I wonder if this could cause #15427 (comment) where I saw a deadlock in paypal express.

@IvanChepurnyi
Copy link
Contributor Author

IvanChepurnyi commented Dec 9, 2019

@convenient This issue might have caused dozens of adverse effects since the introduction of transactions in guest order placement API. Your deadlock most probably a combination of both factors, this issue and REPEATABLE-READ transaction mode in MySQL when the table gets locked for inserting new records if any transaction has a locking gap in the index for new increment value.
I use for all merchants READ-COMMITED mode that does not have any gap locks, so even if such problem exists inserting to table is possible.

@convenient
Copy link
Contributor

Thank you @IvanChepurnyi I will look into the READ-COMMITTED mode.

@ccrothers
Copy link

@sdzhepa Any updates?
Noticed this fix didn't make it into January's 2.3.4 release.
Is this feature on track to be included in the April 28th release of 2.3.5 M2 Commerce?
https://devdocs.magento.com/release/

@sdzhepa
Copy link
Contributor

sdzhepa commented Mar 9, 2020

Hello @ccrothers

Internal Jira ticket related to 2.4 MC-29335 still in open status

@sdzhepa
Copy link
Contributor

sdzhepa commented Mar 10, 2020

FYI: @ccrothers @IvanChepurnyi @convenient @PascalBrouwers @rhoerr

cc: @naydav @andrewbess

One more update
After investigation of all internal Jira tickets related to this bug
I found that it was fixed in the scope of other Jira tasks.
Here is a small summary:

  • in MC-29206 the issue has been fixed for 2.3.x version and should be available with the next 2.3.5 release.
  • in MC-29426 the issue has been fixed for 2.4.x and should be available with the next 2.4.0 release. Commit 43e41fa

May I ask to confirm:

  • is it fixed and we can close the issue
  • or we need to reopen and escalate it one more time?

@IvanChepurnyi
Copy link
Contributor Author

That solution looks like not completely fixes a problem, as sales rule usage update still potentially causes deadlock under high load when a lot of concurrent orders are placed at the same time. The only way to fix this problem is by introducing the append-only event log of sales rule counter adjustment log and using cronjob to update sales rule table.

@sodhancha
Copy link

@engcom-Charlie what is the timeline for this release ?

@viktym
Copy link
Contributor

viktym commented Dec 10, 2020

@sodhancha The internal team resolved the issue - async processing for the coupon/rule usage was implemented. PR with the solution will be delivered in the 2.4-develop branch during the next 2 weeks.

@o-iegorov
Copy link
Contributor

The changes already merged into 2.4-develop. Commit id: a18bfe0

@sdzhepa
Copy link
Contributor

sdzhepa commented Dec 15, 2020

Due to the comments above issue is fixed and delivered
Closed as fixed

@johnorourke
Copy link
Contributor

This also fixes #18752 - exception thrown during payment capture causes a poor error for the user and the exception log contains "Rolled back transaction has not been completed correctly"

@zcuric
Copy link

zcuric commented Jan 19, 2021

The changes already merged into 2.4-develop. Commit id: a18bfe0

Can this be extracted to a plugin for the time being? I don't have very much experience with plugin development.

@hubertus2017
Copy link

hubertus2017 commented Jan 28, 2021

..lost 3% of payments…and tons of hours… will this fix be implemented in Magento 2.4.2? i cant find it in the release notes.

to be clear: I do have magento 2.4.1

Remark from Gene commerce, who are responsible for the bundlked braintree plugin:

We have seen numbers of merchants who faced the same issue where the Orders do not appear in Magento but they appear in Braintree Transaction. We had spent numbers of hours on this issue last year and at the end, it was found that this issue was from Magento end. We contacted Magento and they informed that this issue was fixed and fix is available from Magento 2.4 onwards.

@zcuric
Copy link

zcuric commented Feb 1, 2021

@hubertus2017 05.02.2020. is release day for 2.4.2. Hope this get's fixed, we are having a lot of problems because of this.

@sdzhepa
Copy link
Contributor

sdzhepa commented Feb 5, 2021

Hello @zcuric @hubertus2017

jFYI: #31967 (comment)

based on internal Jira ticket MC-29335 target version is 2.4.3

@zcuric
Copy link

zcuric commented Feb 6, 2021

Hello @zcuric @hubertus2017

jFYI: #31967 (comment)

based on internal Jira ticket MC-29335 target version is 2.4.3

Oh boy, so not in 2.4.2? Man, this is disappointing. Can some please make a patch or extension that fixes this?

@zcuric
Copy link

zcuric commented Feb 9, 2021

@sdzhepa has this landed in 2.4.2?

@magento-quality-patches

The patch solving a similar issue is available in Magento Quality Patches package (MQP)

Patch
MDVA-31519: Fixes the issue where missing paid orders and lock wait timeouts in Guest Checkout.

Compatible versions
Magento OpenSource/Commerce/Commerce Cloud 2.3.5, 2.3.5-p1, 2.3.5-p2

⚠️ We strongly recommend testing all patches in a staging or development environment before deploying to production.

Applying a patch - Magento OpenSource/Commerce

  1. $ composer require magento/quality-patches
  2. $ ./vendor/bin/magento-patches apply MDVA-31519

See MQP Magento Commerce documentation

Applying a patch - Magento Commerce Cloud
See MQP Magento Commerce Cloud documentation

Patch Details
https://support.magento.com/hc/en-us/articles/360055441412

@magento-quality-patches

@zcuric ^^^

@sodhancha
Copy link

sodhancha commented Feb 12, 2021 via email

@zcuric
Copy link

zcuric commented Feb 12, 2021

This is not compatible with EE 2.4.0 Please provide a patch which is compatible with EE 2.4.0

On Thu, Feb 11, 2021 at 4:12 AM Magento Quality Patches < @.***> wrote: @zcuric https://github.com/zcuric ^^^ — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#25862 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIA3O7RJ76UAYW4GHHYKQTS6MB3VANCNFSM4JTGWT7A .
-- Regards, Sodhan Manandhar

@magento-quality-patches

@paragpadsumbiya
Copy link

@zcuric
We have faced same issue with our client as well and as we can see we didn't found issue in normal days but when there was a sale and there was lot of traffic on site then we faces this issue that Authorize.net have paid orders but we didn't found those orders in system . So is there any solution for this ?

@sodhancha
Copy link

Opening this again. This issue has occured for customers who are not GUEST

@LillyDrogerie
Copy link

Confirming that this happens relatively often on EE 2.4.2 as well. The payment processor finish the transaction, but the quote for the given order doesn't exists (anymore?), thus the order creation cannot be finished, leading to the customer being charged but order never created thus cannot be fulfilled. Its annoying because there is no specific rule to debug, it can happen with registered users as well with guest accounts, but no clear reason why exactly it happens. Not to mention that it ruins the reputation of the website...

@chriswatt
Copy link

Experiencing the same problem on Magento 2.4.4 - Customer placed an order, our payment provider (Stripe) charged the customer. The payment references the Magento order number, however that order number doesn't exist

image

image

@WakizashiYoshikawa
Copy link

We have managed to narrow it down to the point of basically a racing condition... You can relatively easily reproduce it.

  1. set the stock of the product to 1
  2. Add it to cart and go to the checkout
  3. Emulate the slow internet connection and initiate electronic payment (Stripe, paypal etc)
  4. Start checkout payment, In our case user is transferred to the 3rd party payment gateway with increment_id of the Magento order so we had plenty of time to finish step 5
  5. Meanwhile drop the stock to 0 in magento backend (basically emulate racing condition)
  6. Finalize the payment on Stripe/PayPal etc
  7. The payment will be processed by Stripe/PP, the callback will be sent, but Magento will fail to create the order since the stock is 0

Hope it helps someone...

@chriswatt
Copy link

chriswatt commented Apr 2, 2025

Still experiencing the same issue. Another order from a customer that is missing from magento but the customer was charged via Stripe.

Magento 2.4.7-p2.

Can this issue please be re-opened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CD Issue recommended for the contribution day Component: Checkout Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Triage: Performance
Projects
Archived in project
Development

No branches or pull requests