Skip to content

Deadlock while updating times_used #40009

Closed
@senthilengg

Description

@senthilengg

Preconditions and environment

  • Magento Version 2.4.8

Steps to reproduce

Multiple No Coupon Rule

  1. Create 3 no coupon rules and ensure each of them applicable to 3 different items (sku conditions)
  2. Login & add the item matching 3rd rule first, item matching 1st rule and item matching 2nd rule
  3. 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
  4. Place order at the same time concurrently
  5. 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

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/SalesRule/etc/db_schema.xml#L131

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.

  1. https://github.com/magento/magento2/blob/2.4.8/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrement.php#L52
  2. 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

  1. Deadlock may occur when you place order with multiple coupons and it conflicts the order in which times_used get updated.
  2. 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

m2-assistant commented on Jun 18, 2025

@m2-assistant

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.


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

m2-assistant commented on Jun 18, 2025

@m2-assistant

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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!
    5. Add label Issue: Confirmed once verification is complete.
    6. Make sure that automatic system confirms that report has been added to the backlog.
added a commit that references this issue on Jun 18, 2025
741b5c4
added 2 commits that reference this issue on Jun 19, 2025
f23a967
57d8d10
removed their assignment
on Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Reported on 2.4.8Indicates original Magento version for the Issue report.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @senthilengg@engcom-November

      Issue actions

        Deadlock while updating times_used · Issue #40009 · magento/magento2