Assume we run the cron every 2 minute (120 seconds). In one cron run a fatal error occurs. Then the semaphore is not reset. Therefore we have a lock for 240 seconds (this value is hard coded in the function drupal_cron_run).
Since we try to start the cron every 120 seconds, the lock is renewed for 240 seconds and the cron will never run again.
This look of 240 seconds should be dynamically set to the max_execution_time, because after this limit the script is die or the server will halt the script.
The line "if (!lock_acquire('cron', 240.0))" should be changed to "if (!lock_acquire('cron', ini_get('max_execution_time'))".
Comments
Comment #1
berdirSince we try to start the cron every 120 seconds, the lock is renewed for 240 seconds and the cron will never run again.
That sounds strange to me. The lock shouldn't be renewed if you can't get the lock. If what you're describing really happens, then that is IMHO the bug here.
Setting the lock time is not as easy as you suggest, max_execution_time might be disabled completely for example. I also think it's not a strict value since it will for example not include query time (AFAIK).
Comment #2
hunziker commentedThank you for your reply.
The problem is that the lock is renewed even though you can't get the lock.
This fix #978944: Handle exceptions thrown in cron seems to resolve the problem with the cron, but only because a shutdown method is registered.
If one of the cron scripts run longer than the max execution time, the look is may be not removed.
Comment #2.0
hunziker commentedcorrect spelling
Comment #4
eric115 commentedThis does seem to be an issue in the lock_aquire function, specifically around line 109 (https://github.com/drupal/drupal/blob/fada06694312023535909764524ab43c99...) where it attempts to extend the amount of time the lock is valid for, which seems like it could cause the issue described here if cron was running more frequently than the lock timeout.
However, given the age of this issue and this being Drupal 7, I think we should close this issue as "Won't fix" due to it being unlikely to be patched or changed now.