Issue #3564915: Fix WSOD during container compilation in D11

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/RedisBackend.php: Add try-catch for ContainerNotInitializedException
  • tests/src/Kernel/RedisBackendContainerCompatibilityTest.php: Kernel tests for the fix

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