[HttpKernel] Fix race condition when clearing old containers

This commit is contained in:
Nicolas Grekas 2017-11-29 10:06:19 +01:00
parent 1f14f4d836
commit 9d553f533f

View File

@ -644,19 +644,18 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
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')) {