Closed
Description
During Black Friday we found random deadlocks during trying to send new order emails.
Analyzing of these cases a bit not obvious - Magento actually saves whole order object, and it saves all the order items JUST FOR setting flag that email was sent for the order. As result under high load we're having deadlocks like this:
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: UPDATE `sales_order_item` SET `order_id` = ?, `parent_item_id` = ?, `quote_item_id` = ?, `store_id` = ?, `created_at` = '2020-11-28 23:33:44', `product_id` = ?, `product_type` = ?, `product_options` = ?, `weight` = ?, `is_virtual` = ?, `sku` = ?, `name` = ?, `description` = ?, `applied_rule_ids` = ?, `additional_data` = ?, `is_qty_decimal` = ?, `no_discount` = ?, `qty_backordered` = ?, `qty_canceled` = ?, `qty_invoiced` = ?, `qty_ordered` = ?, `qty_refunded` = ?, `qty_shipped` = ?, `base_cost` = ?, `price` = ?, `base_price` = ?, `original_price` = ?, `base_original_price` = ?, `tax_percent` = ?, `tax_amount` = ?, `base_tax_amount` = ?, `tax_invoiced` = ?, `base_tax_invoiced` = ?, `discount_percent` = ?, `discount_amount` = ?, `base_discount_amount` = ?, `discount_invoiced` = ?, `base_discount_invoiced` = ?, `amount_refunded` = ?, `base_amount_refunded` = ?, `row_total` = ?, `base_row_total` = ?, `row_invoiced` = ?, `base_row_invoiced` = ?, `row_weight` = ?, `base_tax_before_discount` = ?, `tax_before_discount` = ?, `ext_order_item_id` = ?, `locked_do_invoice` = ?, `locked_do_ship` = ?, `price_incl_tax` = ?, `base_price_incl_tax` = ?, `row_total_incl_tax` = ?, `base_row_total_incl_tax` = ?, `discount_tax_compensation_amount` = ?, `base_discount_tax_compensation_amount` = ?, `discount_tax_compensation_invoiced` = ?, `base_discount_tax_compensation_invoiced` = ?, `discount_tax_compensation_refunded` = ?, `base_discount_tax_compensation_refunded` = ?, `tax_canceled` = ?, `discount_tax_compensation_canceled` = ?, `tax_refunded` = ?, `base_tax_refunded` = ?, `discount_refunded` = ?, `base_discount_refunded` = ?, `free_shipping` = ?, `gift_message_id` = ?, `gift_message_available` = ?, `weee_tax_applied` = ?, `weee_tax_applied_amount` = ?, `weee_tax_applied_row_amount` = ?, `weee_tax_disposition` = ?, `weee_tax_row_disposition` = ?, `base_weee_tax_applied_amount` = ?, `base_weee_tax_applied_row_amnt` = ?, `base_weee_tax_disposition` = ?, `base_weee_tax_row_disposition` = ?, `osc_gift_wrap_amount` = ?, `base_osc_gift_wrap_amount` = ?, `mp_reward_earn` = ?, `mp_reward_spent` = ?, `mp_reward_base_discount` = ?, `mp_reward_discount` = ? WHERE (item_id='1644918')
The stack trace was following:
/path/to/magento2/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:613
/path/to/magento2/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:635
/path/to/magento2/vendor/magento/module-sales/Model/ResourceModel/EntityAbstract.php:182
/path/to/magento2/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:419
/path/to/magento2/vendor/magento/module-sales/Model/Order/ItemRepository.php:176
/path/to/magento2/vendor/magento/module-sales/Model/ResourceModel/Order/Relation.php:74
/path/to/magento2/vendor/magento/framework/Model/ResourceModel/Db/VersionControl/RelationComposite.php:48
/path/to/magento2/vendor/magento/framework/Model/ResourceModel/Db/VersionControl/AbstractDb.php:57
/path/to/magento2/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:424
/path/to/magento2/vendor/magento/module-sales/Model/ResourceModel/Order.php:178
/path/to/magento2/vendor/magento/module-sales/Model/EmailSenderHandler.php:113
/path/to/magento2/vendor/magento/module-sales/Cron/SendEmails.php:46
/path/to/magento2/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:350
/path/to/magento2/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:809
/path/to/magento2/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:776
/path/to/magento2/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:267
/path/to/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
/path/to/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
/path/to/magento2/vendor/magento/framework/Event/Manager.php:66
/path/to/magento2/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
/path/to/magento2/vendor/magento/framework/App/Cron.php:86
/path/to/magento2/vendor/magento/module-cron/Console/Command/CronCommand.php:117
/path/to/magento2/vendor/symfony/console/Command/Command.php:255
/path/to/magento2/vendor/magento/framework/Interception/Interceptor.php:58
/path/to/magento2/vendor/magento/framework/Interception/Interceptor.php:138
/path/to/magento2/vendor/magento/framework/Interception/Interceptor.php:153
/path/to/magento2/generated/code/Magento/Cron/Console/Command/CronCommand/Interceptor.php:26
/path/to/magento2/vendor/symfony/console/Application.php:1005
/path/to/magento2/vendor/symfony/console/Application.php:271
/path/to/magento2/vendor/magento/framework/Console/Cli.php:115
/path/to/magento2/vendor/symfony/console/Application.php:147
/path/to/magento2/bin/magento:23
Potentially such behavior might cause issues with double sending new order emails.
Preconditions (*)
- Magento 2.3.6, 2.4-develop
- Enabled async email sending
Steps to reproduce (*)
- Disable cron jobs
- Place an order
- Set breakpoint at and
- Run
php bin/magento cron:run
Expected result (*)
- We should have just tiny SQL for updating one column, not the whole object and all related objects
- so our debug should stop only on 1st breakpoint
Actual result (*)
- We have saving of whole object and all their related objects that causing deadlocks under the load
- so our debug stopping on 1st and 2nd breakpoints
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- 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
Assignees
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedOnce P0 defects have been fixed, a defect having this priority is the next candidate for fixing.The issue has been reproduced on latest 2.4-develop branchAffects critical data or functionality and forces users to employ a workaround.
Type
Projects
Status
Done