Skip to content

Deadlock while updating times_used #40009

Open
@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”.

Metadata

Metadata

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions