magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.58k stars 9.32k forks source link

Deadlock Error in Magento 2 During High Concurrency: Serialization failure on cataloginventory_stock_item Table #39417

Open talsan74 opened 3 hours ago

talsan74 commented 3 hours ago

Preconditions (*)

  1. Magento: 2.4.7
  2. PHP: 8.3
  3. RDS MYSQL: 8.0 16GB Memory

Steps to reproduce (*)

  1. Install Default Magento
  2. Cron for every 1 minitue
  3. Added 10k products
  4. Run Stress Test for 100 users using JMeter
  5. Trying to place order using graphql

Expected result (*)

  1. 100% will be placed

Actual result (*)

Out of 100 orders, a single-digit order is regularly missing. Resource metrics are fine. This issue only occurs during the stress test, not during manual execution. The logs are being retrieved in Magento.

main.ERROR: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: SELECT `si`.* FROM `cataloginventory_stock_item` AS `si` WHERE (item_id IN (4475, 4522, 4679, 8444, 8745)) FOR UPDATE

GraphQL (3:7)
    mutation {
       placeOrder(input: { cart_id: "Zsasfghssdfgghfghghjgs" }) {
         ^
       order {
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: SELECT `si`.* FROM `cataloginventory_stock_item` AS `si` WHERE (item_id IN (4475, 4522, 4679, 8444, 8745)) FOR UPDATE at /var/www/html/vendor/webonyx/graphql-php/src/Error/Error.php:170)
[previous exception] [object] (Magento\\Framework\\DB\\Adapter\\DeadlockException(code: 1213): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: SELECT `si`.* FROM `cataloginventory_stock_item` AS `si` WHERE (item_id IN (4475, 4522, 4679, 8444, 8745)) FOR UPDATE at /var/www/html/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php:672)
[previous exception] [object] (Zend_Db_Statement_Exception(code: 40001): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: SELECT `si`.* FROM `cataloginventory_stock_item` AS `si` WHERE (item_id IN (4475, 4522, 4679, 8444, 8745)) FOR UPDATE at /var/www/html/lib/internal/Magento/Framework/DB/Statement/Pdo/Mysql.php:109)
[previous exception] [object] (PDOException(code: 40001): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction at /var/www/html/lib/internal/Magento/Framework/DB/Statement/Pdo/Mysql.php:90)"} []
m2-assistant[bot] commented 3 hours ago

Hi @talsan74. 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.