Question

After moving to a new server I am getting the MySQL crash [1] issue once a day, which is coming to my email and annoying not to mention potential impact. Any hints on how to debug this issue?

Obviously crash happens on $schedule->save() so I tried to wrap it with a try ... catch but that didn't help

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
Trace:
#0 /var/www/vhosts/site/store/lib/Zend/Db/Adapter/Pdo/Abstract.php(305): PDO->beginTransaction()
#1 /var/www/vhosts/site/store/lib/Zend/Db/Adapter/Abstract.php(495): Zend_Db_Adapter_Pdo_Abstract->_beginTransaction()
#2 /var/www/vhosts/site/store/lib/Varien/Db/Adapter/Pdo/Mysql.php(219): Zend_Db_Adapter_Abstract->beginTransaction()
#3 /var/www/vhosts/site/store/app/code/core/Mage/Core/Model/Resource/Abstract.php(76): Varien_Db_Adapter_Pdo_Mysql->beginTransaction()
#4 /var/www/vhosts/site/store/app/code/core/Mage/Core/Model/Abstract.php(313): Mage_Core_Model_Resource_Abstract->beginTransaction()
#5 /var/www/vhosts/site/store/app/code/core/Mage/Cron/Model/Observer.php(125): Mage_Core_Model_Abstract->save()
#6 /var/www/vhosts/site/store/app/code/core/Mage/Core/Model/App.php(1338): Mage_Cron_Model_Observer->dispatch(Object(Varien_Event_Observer))
#7 /var/www/vhosts/site/store/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Cron_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#8 /var/www/vhosts/site/store/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('default', Array)
#9 /var/www/vhosts/site/store/cron.php(46): Mage::dispatchEvent('default')
#10
{main}

Timeout settings:

mysql> show global variables like '%timeout%';
+----------------------------+----------+
| Variable_name              | Value    |
+----------------------------+----------+
| connect_timeout            | 10       |
| delayed_insert_timeout     | 300      |
| innodb_lock_wait_timeout   | 50       |
| innodb_rollback_on_timeout | OFF      |
| interactive_timeout        | 30       |
| lock_wait_timeout          | 31536000 |
| net_read_timeout           | 30       |
| net_write_timeout          | 60       |
| slave_net_timeout          | 3600     |
| wait_timeout               | 3600     |
+----------------------------+----------+
10 rows in set (0.00 sec)
Was it helpful?

Solution

As others have said it's likely triggered by a long running script. Any script that takes a long time to run without using the database can potentially timeout.

I've had this happen before. We have a script that connects to a remote server, downloads a few hundred xml files, parses and converts them into a .csv file for import via the built in Magento ImportExport module. We have a custom logging module, which allows us to track what happened with our routines. The very first thing the class does, is add a row to this log table to say routine started. It then takes 5-10 minutes to fetch the remote xml files. After downloading the files it attempts to write another log entry to say that it's finished. Since the mysql connection has been open since the first log event and hasn't been used since, mysql has closed the connection as it has received no query for longer than the timeout period.

OTHER TIPS

In your /etc/mysql/my.cnf try increasing the value for max_allowed_packet

Eg.

max_allowed_packet = 256M

Then restart MySQL.

If you ask me, it is not a good idea to keep a mysql connection open for hours. So the alternative is, to check, wether the connection still exists, if no, open a new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top