Issue #1484216 by catch, Berdir, beejeebus, tim.plunkett: Fixed Race condition in _update_create_fetch_task() (PDO Exceptions).

merge-requests/26/head
webchick 2012-04-28 13:42:42 -07:00
parent 8f9ee9ec68
commit 00caaed222
1 changed files with 16 additions and 6 deletions

View File

@ -237,12 +237,22 @@ function _update_create_fetch_task($project) {
if (empty($fetch_tasks[$cid])) { if (empty($fetch_tasks[$cid])) {
$queue = DrupalQueue::get('update_fetch_tasks'); $queue = DrupalQueue::get('update_fetch_tasks');
$queue->createItem($project); $queue->createItem($project);
// Due to race conditions, it is possible that another process already
// inserted a row into the {cache_update} table and the following query will
// throw an exception.
// @todo: Remove the need for the manual check by relying on a queue that
// enforces unique items.
try {
db_insert('cache_update') db_insert('cache_update')
->fields(array( ->fields(array(
'cid' => $cid, 'cid' => $cid,
'created' => REQUEST_TIME, 'created' => REQUEST_TIME,
)) ))
->execute(); ->execute();
}
catch (Exception $e) {
// The exception can be ignored safely.
}
$fetch_tasks[$cid] = REQUEST_TIME; $fetch_tasks[$cid] = REQUEST_TIME;
} }
} }