Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor #25205 [HttpKernel] Fix race condition when clearing old contai…
…ners (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 #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
  • Loading branch information
fabpot committed Nov 29, 2017
2 parents f74eced + 9d553f5 commit 5cb6c93
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -644,19 +644,18 @@ protected function initializeContainer()
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')) {
Expand Down

0 comments on commit 5cb6c93

Please sign in to comment.