From 9d553f533f3c4d3ea00145f785b79c86305d3186 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 29 Nov 2017 10:06:19 +0100 Subject: [PATCH] [HttpKernel] Fix race condition when clearing old containers --- src/Symfony/Component/HttpKernel/Kernel.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 62f71d622281..789eb268cf5a 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -644,19 +644,18 @@ protected function initializeContainer() return; } - if ($oldContainer) { + if ($oldContainer && get_class($this->container) !== $oldContainer->name) { // Because concurrent requests might still be using them, // old container files are not removed immediately, // but on a next dump of the container. $oldContainerDir = dirname($oldContainer->getFileName()); foreach (glob(dirname($oldContainerDir).'/*.legacyContainer') as $legacyContainer) { - if (@unlink($legacyContainer)) { + if ($oldContainerDir.'.legacyContainer' !== $legacyContainer && @unlink($legacyContainer)) { (new Filesystem())->remove(substr($legacyContainer, 0, -16)); } } - if (get_class($this->container) !== $oldContainer->name) { - touch($oldContainerDir.'.legacyContainer'); - } + + touch($oldContainerDir.'.legacyContainer'); } if ($this->container->has('cache_warmer')) {