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()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/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:
-
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