Commit 93639aac authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix race condition in cron (bug #891170)



When cron finds a function with a stale (day-old) lock, just remove
the lock and give up rather than trying to execute the function again.
It's already pretty late, and waiting another minute for the next cron
to start won't make a difference.

This should avoid the case where two copies of cron both find the stale
lock at the same time, and restart simultaneously.  It won't matter if
cron_lock fails to get a $started value because the row has been
deleted: the next instance of cron to run will be able to insert the
row.

Change-Id: I025aaf89d64f47466f1ba4c5bb8178317277ec2c
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent db5e8575
......@@ -492,12 +492,11 @@ function cron_lock($job, $start, $plugintype='core') {
$strstart = $started ? date('r', $started) : '';
$msg = "long-running cron job $jobname ($strstart).";
// If it's been going for more than 24 hours, start another one anyway
// If it's been going for more than 24 hours, remove the lock
if ($started && $started < $start - 60*60*24) {
delete_records('config', 'field', $lockname);
insert_record('config', (object) array('field' => $lockname, 'value' => $start));
log_debug('Restarting ' . $msg);
return true;
log_debug('Removing lock record for ' . $msg);
cron_free($job, $started, $plugintype);
return false;
}
log_debug('Skipping ' . $msg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment