Drupal Tip: Forcing cron to get un-stuck

I just wasted the better part of an hour trying to troubleshoot a "cron run failed" error on one of my Drupal sites (oddly, only one of four was affected). Trying to run cron manually from the status page gives a "cron run failed" error, and looking at the "Recent log entries" (aka watchdog, apparently) showed a message "Attempting to re-run cron while it is already running".

I did a bit of searching for a resolution to this, there is a bit of discussion about this on the main Drupal site, and at least one other site. You will notice in both places, that a suggested fix is to use phpMyAdmin to manually delete the "cron_semaphore" and "cron_last" from the variables table.

cron_semaphore is, indeed the culprit, but in my case, deleting the cron_semaphore from the database did not help. All I can think of, is that the database query result was being cached s.t. even though cron_semaphore was not set in the database, PHP was still picking it up. To fix this, what I ended up doing was temporarily modifying common.inc drupal_cron_run() to disable the semaphore entirely:

  // Fetch the cron semaphore
  //$semaphore = variable_get('cron_semaphore', FALSE);
  $semaphore = FALSE;

Making this change disables the semaphore mechanism entirely and allows cron to run. After doing this, I checked the variables table and sure enough the cron_last variable could be seen to be updated. I then re-enabled the semaphore (put the original common.inc back) and so far, everything seems to be o.k.

Note that some of you reading this might be tempted to just leave the semaphore disabled. And if you can be 100% certain you'll never get two crons running at the same time, it is probably safe to do so. I wouldn't recommend it though; instead, think of this as an emergency measure to get the cron_semaphore un-stuck when doing so using the database method doesn't work.

Thanks for this solution,

Thanks for this solution, deleting the cron_semaphore from the DB didn't help for me either.
But editing the common.inc file did (and yeah I changed it again after running cron Sticking out tongue), thumbs up!

Greetings

Thanks! Worked like a charm.

Thanks! Worked like a charm.

Perfect. Be nice if Drupal

Perfect. Be nice if Drupal could report the error with a little more clues when cron sticks. Please keep this page live forever - you're a cron saver Eye-wink

Thank you so much! You saved

Thank you so much! You saved me a lot of time Smiling

Thanks for the solution, its

Thanks for the solution, its great and so simple.
I had "cron run failed" issue few minutes ago, and i follow your step, and it just solve my problem.
Thanks.

All those people @ d.o

All those people @ d.o weren't able to come up with such a simple hack to fix the cron-stuck-problem.

but, you did and it worked! Thanks Smiling

This tip was a life-saver.

This tip was a life-saver. Thanks!

Thanks for this, I'm

Thanks for this, I'm importing a ton of data from a different database to build a drupal site and got a little impatient and overzealous during the indexing... next thing you know cron was stuck indexing at 85% and the database method wasn't working.. this one worked like a charm though. Thanks a ton.

This did the trick. Thanks!

This did the trick. Thanks!

Thanks this was helpful. I

Thanks this was helpful. I didn't go so far though. After deleting semaphor AND clearing cache under administer>performance the problem was solved. The cache table DOES cache variables.

Great, thanks for this. I

Great, thanks for this. I had the same problem with cron still failing after deleting the database entry. After reading this I thought to go to admin/settings/performance and clear all caches; that sorted it out too.

Very helpful! Many thanks

Very helpful! Many thanks for taking the time to post.

Best,
Shane

This tip just saved my butt

This tip just saved my butt on a project with a tight deadline. Thank you very kindly for putting this out there for Google to find and lead me to! Smiling

For good or ill, yours is

For good or ill, yours is the only solution to this problem I have found. And, I admit, I just might be tempted to just leave the semaphore disabled. Well done!