diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index a4b17e2..ea2c661 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -121,6 +121,21 @@ public function __construct(MatcherDumperInterface $dumper, LockBackendInterface } /** + * Checks that there is really no rebuild needed. + * + * @see https://drupal.org/node/356399 + */ + protected function checkRebuildNeeded() { + // To absolutely ensure that the router rebuild is required, re-load the + // variables in case they were set by another process. + $this->routeBuilderIndicator->resetCache(); + if ($this->routeBuilderIndicator->isRebuildNeeded()) { + return TRUE; + } + return FALSE; + } + + /** * {@inheritdoc} */ public function rebuild() { @@ -133,6 +148,11 @@ public function rebuild() { // We choose to block here since otherwise the routes might not be // available, resulting in a 404. $this->lock->wait('router_rebuild'); + + if ($this->checkRebuildNeeded()) { + $this->rebuild(); + } + return FALSE; } diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php index 5f06120..a3ae80a 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php @@ -31,6 +31,10 @@ public function __construct(StateInterface $state) { $this->state = $state; } + public function resetCache() { + $this->state->resetCache(); + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php index 68ce5b8..3178174 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php @@ -15,6 +15,11 @@ const REBUILD_NEEDED = 'router_rebuild_needed'; /** + * Reset the router cache. + */ + public function resetCache(); + + /** * Sets the router to be rebuilt next time the kernel is terminated. * * @see \Drupal\Core\EventSubscriber\RouterRebuildSubscriber::onKernelTerminate()