diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index e09d9f6..3162bbc 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -127,7 +127,10 @@ public function loadTemplate($name, $index = NULL) { $this->updateCompiledTemplate($cache_filename, $name); } - if (!$this->storage()->load($cache_filename)) { + // Load the file, double-check that the class now exists to prevent + // rare race conditions in the storage. + if (!$this->storage()->load($cache_filename) || !class_exists($cls)) { + //if (!$this->storage()->load($cache_filename)) { $this->updateCompiledTemplate($cache_filename, $name); $this->storage()->load($cache_filename); } diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index 8edb4b2..d5179c6 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Theme; use Drupal\Component\Utility\String; +use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Site\Settings; use Drupal\simpletest\KernelTestBase; @@ -44,6 +45,19 @@ public function testInlineTemplate() { ); $this->assertEqual(drupal_render($element), 'test-with-context ' . String::checkPlain($unsafe_string)); + // Simulate an invalid, existing file in the storage. + $name = 'invalid file'; + $cache_file = $environment->getCacheFilename($name); + $storage = PhpStorageFactory::get('twig'); + $storage->save($cache_file, ' 'inline_template', + '#template' => $name, + ); + $this->assertEqual(drupal_render($element), $name); + // Enable twig_auto_reload and twig_debug. $settings = Settings::getAll(); $settings['twig_debug'] = TRUE;