Issue #3564915: Fix WSOD during container compilation in D11 (backport to 8.x-1.x)

Problem

On Drupal 11, sites using Redis as a cache backend experience a White Screen of Death (WSOD) with ContainerNotInitializedException during container compilation.

This occurs because HookCollectorKeyValueWritePass clears caches during compilation. At this point:

  • \Drupal::hasContainer() returns TRUE (container object exists)
  • But \Drupal::database() throws ContainerNotInitializedException because the database service isn't registered yet

Solution

Wrap the \Drupal::database() call in a try-catch block to handle ContainerNotInitializedException gracefully:

$in_transaction = FALSE;
if (\Drupal::hasContainer()) {
  try {
    $in_transaction = \Drupal::database()->inTransaction();
  }
  catch (ContainerNotInitializedException $e) {
    // Container exists but database service is not yet available.
  }
}

Changes

  • src/Cache/CacheBase.php: Add try-catch for ContainerNotInitializedException
  • tests/src/Kernel/CacheBaseContainerCompatibilityTest.php: Kernel tests for the fix

Why Backport?

Some organizations have constraints that prevent immediate upgrades:

  • Locked versions due to security review processes
  • Compatibility requirements with other modules
  • Testing requirements before major version upgrades

This minimal, focused fix allows affected sites to run Drupal 11 with Redis 1.x without upgrading to 2.x.

Testing

The kernel test verifies:

  1. deleteMultiple() works during normal operation
  2. deleteMultiple() handles empty arrays safely
  3. deleteMultiple() handles non-existent cache IDs
  4. Container rebuild completes without Redis-related errors
  5. deleteAll() continues to work correctly

Merge request reports

Loading