Skip to content

Commit

Permalink
bug #25190 [HttpKernel] Keep legacy container files for concurrent re…
Browse files Browse the repository at this point in the history
…quests (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Keep legacy container files for concurrent requests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25177
| License       | MIT
| Doc PR        | -

Because concurrent requests might still be using them,
old container files should not be removed immediately,
but on a next dump of the container.

Commits
-------

ee3b6fe [HttpKernel] Keep legacy container files for concurrent requests
  • Loading branch information
fabpot committed Nov 29, 2017
2 parents 3c8ff5e + ee3b6fe commit 1f14f4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -644,8 +644,19 @@ protected function initializeContainer()
return;
}

if ($oldContainer && get_class($this->container) !== $oldContainer->name) {
(new Filesystem())->remove(dirname($oldContainer->getFileName()));
if ($oldContainer) {
// 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)) {
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
}
}
if (get_class($this->container) !== $oldContainer->name) {
touch($oldContainerDir.'.legacyContainer');
}
}

if ($this->container->has('cache_warmer')) {
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -832,7 +832,8 @@ public function testKernelReset()
$kernel->boot();

$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
$this->assertFileNotExists($containerFile);
$this->assertFileExists($containerFile);
$this->assertFileExists(dirname($containerFile).'.legacyContainer');
}

public function testKernelPass()
Expand Down

0 comments on commit 1f14f4d

Please sign in to comment.