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()returnsTRUE(container object exists) - But
\Drupal::database()throwsContainerNotInitializedExceptionbecause 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:
-
deleteMultiple()works during normal operation -
deleteMultiple()handles empty arrays safely -
deleteMultiple()handles non-existent cache IDs - Container rebuild completes without Redis-related errors
-
deleteAll()continues to work correctly