From 00caaed22268b95d909c6a9fcce51e92a709f79b Mon Sep 17 00:00:00 2001 From: webchick Date: Sat, 28 Apr 2012 13:42:42 -0700 Subject: Issue #1484216 by catch, Berdir, beejeebus, tim.plunkett: Fixed Race condition in _update_create_fetch_task() (PDO Exceptions). --- modules/update/update.fetch.inc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'modules/update') diff --git a/modules/update/update.fetch.inc b/modules/update/update.fetch.inc index 7ac0dbefb..88132cec3 100644 --- a/modules/update/update.fetch.inc +++ b/modules/update/update.fetch.inc @@ -237,12 +237,22 @@ function _update_create_fetch_task($project) { if (empty($fetch_tasks[$cid])) { $queue = DrupalQueue::get('update_fetch_tasks'); $queue->createItem($project); - db_insert('cache_update') - ->fields(array( - 'cid' => $cid, - 'created' => REQUEST_TIME, - )) - ->execute(); + // 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') + ->fields(array( + 'cid' => $cid, + 'created' => REQUEST_TIME, + )) + ->execute(); + } + catch (Exception $e) { + // The exception can be ignored safely. + } $fetch_tasks[$cid] = REQUEST_TIME; } } -- cgit v1.2.3