Fixed Crons stopped running


Well-known member
Under 1.2.0, my crons would stop every couple days (mainly because of some Twitter API stuff I was doing and when the Twitter API failed, it would cause an error while running the cron).

This was fixed in 1.2.1, but I still ran into an issue where the cron tasks just stopped working again (only has happened once).

I did some checking around in the code, and I suspect it's the
XenForo_Model_Cron::getMinimumNextRunTime() method that can cause crons to stop working every once in a blue moon.

If the query it runs fails for whatever reason, cron will effectively stop running (maybe there's a locking issue and the query times out... maybe you are in the middle of restarting MySQL so it went away for a split second while that query ran, etc.)

If that query returns nothing, the system sets the next cron run time to January 19, 2038.

In theory that cron should *never* return nothing unless all crons are disabled.

It probably would be a better idea to fall back to a default next run time of something more reasonable... like 15 minutes in the future, rather than never checking again for crons to run until 2038.


XenForo developer
Staff member
The fallback is probably reasonable, but I think it's very unlikely that is the cause -- it's likely still a potential race condition that's wiping out the deferred process. I have already tweaked this again for 1.2.2 as I realized that there was a situation where a fatal error could still trigger a problem, particularly on a busy site. I think that fits you... ;)

If it happens again, before you fix it, look at your xf_deferred table. If you don't see a "Cron" entry, then you got hit by the race condition.


Well-known member
Not sure what the race condition that was tweaked in 1.2.2 was, but would it apply to a setup that the deferred.php only runs once a minute? We removed the system that triggers it from page views and instead trigger deferred.php every minute from a single server via crontab.

* * * * *       root    /usr/local/bin/php /home/sites/ > /dev/null 2>&1


Well-known member
Haven't upgraded to 1.2.2 yet, but happened again today. The xf_deferred table has no records in it... so I hopefully it's whatever was fixed in 1.2.2. There also wasn't a MailQueue entry in there until we disabled/reenabled a random cron.