Skip to content

Commit 5cb6c93

Browse files
committed
minor symfony#25205 [HttpKernel] Fix race condition when clearing old containers (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [HttpKernel] Fix race condition when clearing old containers | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Missed in symfony#25190: when two concurrent requests create the new container concurrently, the last one would drop the old container files, because the first one just created the `*.legacyContainer` file. Commits ------- 9d553f5 [HttpKernel] Fix race condition when clearing old containers
2 parents f74eced + 9d553f5 commit 5cb6c93

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)