Skip to content

Commit 9d553f5

Browse files
[HttpKernel] Fix race condition when clearing old containers
1 parent 1f14f4d commit 9d553f5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,19 +644,18 @@ protected function initializeContainer()
644644
return;
645645
}
646646

647-
if ($oldContainer) {
647+
if ($oldContainer && get_class($this->container) !== $oldContainer->name) {
648648
// Because concurrent requests might still be using them,
649649
// old container files are not removed immediately,
650650
// but on a next dump of the container.
651651
$oldContainerDir = dirname($oldContainer->getFileName());
652652
foreach (glob(dirname($oldContainerDir).'/*.legacyContainer') as $legacyContainer) {
653-
if (@unlink($legacyContainer)) {
653+
if ($oldContainerDir.'.legacyContainer' !== $legacyContainer && @unlink($legacyContainer)) {
654654
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
655655
}
656656
}
657-
if (get_class($this->container) !== $oldContainer->name) {
658-
touch($oldContainerDir.'.legacyContainer');
659-
}
657+
658+
touch($oldContainerDir.'.legacyContainer');
660659
}
661660

662661
if ($this->container->has('cache_warmer')) {

0 commit comments

Comments
 (0)