8000 [HttpKernel] Keep legacy container files for concurrent requests · symfony/symfony@ee3b6fe · GitHub
[go: up one dir, main page]

Skip to content

Commit ee3b6fe

Browse files
[HttpKernel] Keep legacy container files for concurrent requests
1 parent a19d1e5 commit ee3b6fe

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,19 @@ protected function initializeContainer()
643643
return;
644644
}
645645

646-
if ($oldContainer && get_class($this->container) !== $oldContainer->name) {
647-
(new Filesystem())->remove(dirname($oldContainer->getFileName()));
646+
if ($oldContainer) {
647+
// Because concurrent requests might still be using them,
648+
// old container files are not removed immediately,
649+
// but on a next dump of the container.
650+
$oldContainerDir = dirname($oldContainer->getFileName());
651+
foreach (glob(dirname($oldContainerDir).'/*.legacyContainer') as $legacyContainer) {
652+
if (@unlink($legacyContainer)) {
653+
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
654+
}
655+
}
656+
if (get_class($this->container) !== $oldContainer->name) {
657+
touch($oldContainerDir.'.legacyContainer');
658+
}
648659
}
649660

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

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ public function testKernelReset()
832832
$kernel->boot();
833833

834834
$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
835-
$this->assertFileNotExists($containerFile);
835+
$this->assertFileExists($containerFile);
836+
$this->assertFileExists(dirname($containerFile).'.legacyContainer');
836837
}
837838

838839
public function testKernelPass()

0 commit comments

Comments
 (0)
0