Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.0-beta8
Description: 

In Drupal 7 and earlier versions of Drupal 8, route rebuilding was triggered by a global flag (shared between requests),
so the next time some process required routing information, the rebuild was triggered, and a lock is set, which other processes run into as well.

Drupal 7

variable_set('menu_rebuild_needed', TRUE);

Drupal 8

\Drupal::service('router.builder_indicator')->setRebuildNeeded();

This lead to various problems:

  • Bad performance during the rebuilding for multiple processes
  • Race conditions caused by the lock

Drupal 8 (after beta8)

The route rebuild indicator service is removed and replaced by \Drupal\Core\Routing\RouteBuilder->setRebuildNeeded().
At the end of that request, the router is then rebuild, so other processes don't request a rebuild.

If some code wants to cause a router rebuild, the code looks like the following:

\Drupal::service('router.builder')->setRebuildNeeded();

Some edge cases, like automated tests may need to trigger a rebuild immediately (so that new route information is available in the same request already). This is still possible with:

\Drupal::service('router.builder')->rebuild();
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done