Drupal Stuck Cron Jobs : MySQL server has gone away

Stuck Drupal Cron Jobs Some things in Drupal are a pain in the ass to debug. Hanging cron jobs that never seem to end are one of those things. Strange messages start appearing like…

Cron has been running for over an hour and is probably stuck.

or

Attempting to restart Cron

That usually doesn’t leave you with much to work with, does it?

 

First thing to tackle this is try and get the cron unstuck and running. To do that, you can install the Devel module, goto the variable view, and delete the cron_semaphore variable that indicated a cron is already running. After flushing all cache you should be able to run cron again. Then, you might come across various types of the next strange message

MySql : " Warning: MySQL server has gone away "

Gone away where?

 

This indicates that MySQL is timing out. To tackle that you’d need to tweak MySQL a bit. Drupal has a great guide on that. Essentially, it’s opening your /etc/my.cnf and setting it to something that allows longer runs. Following is what I ended up with :

[mysqld]
skip-bdb
set-variable = max_connections=500
safe-show-database

connect_timeout=30
interactive_timeout=45
wait_timeout=45

join_buffer_size=2M
key_buffer_size=384M
max_allowed_packet=64M
myisam_sort_buffer_size=48M
read_buffer_size=2M
sort_buffer_size=2M
read_rnd_buffer_size=64M
myisam_sort_buffer_size = 64M
table_cache=4096
thread_cache_size=96
tmp_table_size=64M
query_cache_limit=1M
query_cache_size=32M
query_cache_type=1

Don’t forget to restart the server and after clearing the cron semaphore again rerun the cron. That should take care of things.

Leave a Comment