-
Notifications
You must be signed in to change notification settings - Fork 9.4k
1213 Deadlock found when trying to get lock #8933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The indexer runs on a schedule by cron! you need to disable that or they need a lock to prevent concurrent access! If you don't mind modifying the database code you can modify aoe's magenta 1 plugin to function the same. I have and it does not solve the longer issues, but can be a lifesaver due to the little short issues! You should really batch all of your product imports when the store is in maintenance mode and then reindex before taking it out of maintenance mode at midnight! At least until magento can develop a decent locking system to work around the cron indexer! |
Thanks for reply.
Thank you |
Sounds like you need to use a dedicated import script. I can import 1M products in about 6 hours time using dedicated script that does direct access to database, but as you have figured out- you cannot manually muck with the categories/products during the same time! IMO the best route would be to offload the product attributes/categories to a nosql based solution so you can side-load the products. I've only seen this done with magento 1 using smile-sa (GitHub) mongodb driver! But if you use smile-sa's elastic suite - the indexing goes much faster! check it out it is free! While reindexing the catalog stays online since it reindexes to a new catalog and does a switcheroo when done! |
Hello, Could you please specify "nosql based solution" ? Thank you |
store all product attributes in mongodb which is far better than EAV-style datastore for tons of products. Better yet - imo - would be to store the attributes in elasticsearch itself! |
Thanks for reply. I have another question regarding indexing.
=> expected result, newly added product should not be in catalog_product_flat table |
I'm not sure, are you sure that cron.php is not being called by crond?! I assumed reindexing was to move from database (flat, or eav) to solr/elasticsearch models on schedule. I would have thought the flat table was directly written to. I've been using elasticsearch since v1 - so i'm not sure how the flat tables get indexed if not real time?! mysql doesn't need any work to add text based indexing! |
I'm having this same issue on magento 2.1.6 and I'm using elasticsearch but my issue seems to be when magento is running a reindex |
Confirm this bug. |
and with v.2.21 |
Confirm |
Magento Version: 2.1.9| Total Products: 18k my client site is marketplace site so, on this site, there are lots of products, customers, and orders adding or updating. But when I tried to reindexing all than after some time exception.log file generated including the following error in this file and server was stuck and then need to restart the server and then after the site is working as normal. "PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction" so please suggest me how can I fix it and what is the best way to reindexing manually or using cron? |
Hi @yj4189 , if you set indexers to "Update on Save" mode, then you should not do full reindex. If you still have deadlock, please provide information from mysql command SHOW ENGINE INNODB STATUS |
Same error happening for me on 2.2.2 |
Same error happening for me on 2.2.3 |
We are facing deadlock issue during catalog_product_attribute reindexing. It gives SQLSTATE[HY000]: General error: 2006 MySQL server has gone away error as MySQL database CPU is 100% utilized. Magento version: 2.1.7 Please suggest what can be done? |
@dimple-ambab , it can be another issue, not related to a deadlock. Please check after error happening status of section LATEST DETECTED DEADLOCK with command "SHOW ENGINE INNODB STATUS" |
I've experienced similar issues... |
This is still an issue on 2.2.4, but only when trying to save products while the indexing is running. |
Same here - We receive that error if a product is saving when the index is running. |
We have the same error with 2.2.5 and PHP 7.1. Below is the cron log. [PDOException] cron:run [--group GROUP] [--bootstrap BOOTSTRAP] [Zend_Db_Adapter_Exception] [PDOException] cron:run [--group GROUP] [--bootstrap BOOTSTRAP] |
In addition, the error message displayed in the browser is: |
Hi @w130pmpo. Thank you for your report and collaboration! The issue was fixed by Magento team. The fix will be available with the upcoming |
Hi @w130pmpo. Thank you for your report and collaboration! The issue was fixed by Magento team. The fix was delivered into
The fix will be available with the upcoming |
@magento-engcom-team links to the commits do not seem to be working |
Hi @w130pmpo. Thank you for your report and collaboration! The issue was fixed by Magento team. The fix will be available with the upcoming |
@magento-engcom-team Can you provide working links to the commits in 2.3.5 that fix this issue, as the commits you posted in your April 24th comment no longer work? |
I face a Similar issue on Magento 2.3.2 PHP 7.3 nginx, mariadb, `root@ip-172-31-XXXXX:/var/www/html/XXXXXX# ### sudo php bin/magento cron:run In Mysql.php line 589: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: DELETE FROM In Mysql.php line 110: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: DELETE FROM In Mysql.php line 91: ^C` ### Solution # fine |
Hi @w130pmpo. Thank you for your report.
The fix will be available with the upcoming 2.4.3 release. |
... the message keeps repeating This is particular interesting to address my concerns about the support. Why this issue is closed when 2.4.3 was not released? Where are the Adobe geniuses? |
I'm not definitely geniues but this fix already confirm delivered to 2.4-develop branch via commit #28007 by @driskell. |
temporary solution is truncate table cron_schedule , issue solved ! |
In our case the problem still occur after upgrading to Magento 2.4.3, so it's probably still not solved. |
Magento 2.4.3-p1 still this error exists... |
Magento 2.4.3 i have the same error when i import product with Php |
2.4.3-p1 same error. Happens with regular import/updates of ~4000+ products. |
If you have an import that runs from within a PHP script, try to lock the indexer cronjobs before you start the import. Here's an example of a Helper class you can use for this, just call the <?php
namespace Vendor\Import\Helper;
use Vendor\Import\Exception\LockException;
use Magento\Cron\Observer\ProcessCronQueueObserver;
use Magento\Framework\Lock\LockManagerInterfaceFactory;
class Lock
{
private $lockManagerFactory;
public function __construct(
LockManagerInterfaceFactory $lockManagerFactory
) {
$this->lockManagerFactory = $lockManagerFactory;
}
private function executeAndLockIndexers(callable $callback)
{
// try to get a lock of the index cronjob group & specific indexer cronjobs
$lockManager = $this->lockManagerFactory->create();
$lockTimeout = 300; // 5 minutes
$cronIndexGroupId = 'index';
$lockName1 = ProcessCronQueueObserver::LOCK_PREFIX . $cronIndexGroupId;
$lockName2 = ProcessCronQueueObserver::LOCK_PREFIX . md5($cronIndexGroupId . '_' . 'indexer_reindex_all_invalid');
$lockName3 = ProcessCronQueueObserver::LOCK_PREFIX . md5($cronIndexGroupId . '_' . 'indexer_update_all_views');
// when we were able to create the lock, the cronjob will not start the indexer jobs (until the import is finished)
// when the indexers are already running by the cronjob, we will wait the amount of seconds specified in the $lockTimeout variable before giving it up
if ($lockManager->lock($lockName1, $lockTimeout)) {
try {
if ($lockManager->lock($lockName2, $lockTimeout)) {
try {
if ($lockManager->lock($lockName3, $lockTimeout)) {
try {
call_user_func_array($callback, []);
} finally {
$lockManager->unlock($lockName3);
}
} else {
throw new LockException("The $lockName3 was locked for more than $lockTimeout seconds, so giving up on this import");
}
} finally {
$lockManager->unlock($lockName2);
}
} else {
throw new LockException("The $lockName2 was locked for more than $lockTimeout seconds, so giving up on this import");
}
} finally {
$lockManager->unlock($lockName1);
}
} else {
throw new LockException("The $lockName1 was locked for more than $lockTimeout seconds, so giving up on this import");
}
}
} It might look a bit ugly, but we have something like this setup on multiple projects (both 2.3.x and 2.4.x Magento versions) and never see a deadlock anymore during imports. As an additional hint: setup your lock provider to use the filesystem instead of the default database, because the database one can fail when you have a high load on your server and/or if your mysql server restarts. See the documentation about how to do this. Hope this helps 🙂 |
Magento 2.4.4 this error still exists |
Still an issue in Magento 2.4.7-p5. In case you havent figured it out out Magento is a joke. The lack of willingness to fix a now 8 years old issue with 150+ comments is one of many you will find when trying to us it. |
The issue: still in Magento v2.4.8 |
Preconditions
Steps to reproduce
Expected result
Actual result
The text was updated successfully, but these errors were encountered: