diff -u b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php --- b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @@ -59,7 +59,18 @@ * Perform menu-specific rebuilding. */ protected function menuLinksRebuild() { - $this->menuLinkManager->rebuild(); + if ($this->lock->acquire(__FUNCTION__)) { + // Ensure the menu links are up to date. + $this->menuLinkManager->rebuild(); + + $this->lock->release(__FUNCTION__); + } + else { + // Wait for another request that is already doing this work. + // We choose to block here since otherwise the router item may not + // be available during routing resulting in a 404. + $this->lock->wait(__FUNCTION__); + } } /** diff -u b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php --- b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -147,25 +147,14 @@ * {@inheritdoc} */ public function rebuild(array $definitions) { - if ($this->lock->acquire(__FUNCTION__)) { - $transaction = $this->connection->startTransaction(); - try { - // Ensure the menu links are up to date. - $this->menuLinkManager->rebuild(); - // Ignore any database replicas temporarily. - db_ignore_replica(); - } - catch (\Exception $e) { - $transaction->rollback(); - watchdog_exception('menu', $e); - } - $this->lock->release(__FUNCTION__); + $transaction = $this->connection->startTransaction(); + try { + // Ignore any database replicas temporarily. + db_ignore_replica(); } - else { - // Wait for another request that is already doing this work. - // We choose to block here since otherwise the router item may not - // be available during routing resulting in a 404. - $this->lock->wait(__FUNCTION__); + catch (\Exception $e) { + $transaction->rollback(); + watchdog_exception('menu', $e); } $links = array();