Closed
Description
Preconditions and environment
- Magento Version 2.4.8
Steps to reproduce
Multiple No Coupon Rule
- Create 3 no coupon rules and ensure each of them applicable to 3 different items (sku conditions)
- Login & add the item matching 3rd rule first, item matching 1st rule and item matching 2nd rule
- Login to another account in an Incognito window and Add the item matching 2nd rule first, item matching 3rd rule and item matching 1st rule
- Place order at the same time concurrently
- If both salesrule_customer update land on DB at the same time then it will get in to a deadlock (https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php#L191)
Reason for the lock on salesrule while updating salesrule_customer
While place order in around submit the below functions will executed and update the rule in the same order in which its there on the quote table which locks the parent table also due to foreign key constraint. But the order in which transactions try to lock will be different based on the order of rule ids applied.
- https://github.com/magento/magento2/blob/2.4.8/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrement.php#L52
- https://github.com/magento/magento2/blob/2.4.8/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php#L198
Expected result
Order should process normally and rule times_used should update without any issue
Actual result
Deadlock updating salesrule times_used and order will fail
Additional information
Optional :: Multiple Coupon Rule
- Deadlock may occur when you place order with multiple coupons and it conflicts the order in which times_used get updated.
- Example if 3 coupon applied 1,2,3 and salesrule_customer update of another transaction for another customer try to update 3,2,1 it will end up in deadlock
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Activity
m2-assistant commentedon Jun 18, 2025
Hi @senthilengg. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.
@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
m2-assistant commentedon Jun 18, 2025
Hi @engcom-November. 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: 👇
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branchDetails
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced 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!
Issue: Confirmed
once verification is complete.Sorting before update coupons times used - to fix magento#40009
Sorting before update coupons times used - to fix magento#40009
PHPCBF fixes- to fix magento#40009