Permalink
Browse files

bug #24419 [Cache] Fix race condition in TagAwareAdapter (nicolas-gre…

…kas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Cache] Fix race condition in TagAwareAdapter

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

This code is not needed, and might create a race condition (see linked issue). Let's drop it.
When no tags are set on an item, this stores an empty tags array, instead of deleting the tags array entry at all.

Commits
-------

fa24fa8 [Cache] Fix race condition in TagAwareAdapter
  • Loading branch information...
fabpot committed Oct 5, 2017
2 parents 417ec3a + fa24fa8 commit fc9acad46e9f49ea2e3b5240cbb65e2c75287ffb
Showing with 2 additions and 9 deletions.
  1. +2 −9 src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
@@ -250,19 +250,12 @@ public function commit()
$f = $this->getTagsByKey;
$tagsByKey = $f($items);
$deletedTags = $this->deferred = array();
$this->deferred = array();
$tagVersions = $this->getTagVersions($tagsByKey);
$f = $this->createCacheItem;
foreach ($tagsByKey as $key => $tags) {
if ($tags) {
$this->itemsAdapter->saveDeferred($f(static::TAGS_PREFIX.$key, array_intersect_key($tagVersions, $tags), $items[$key]));
} else {
$deletedTags[] = static::TAGS_PREFIX.$key;
}
}
if ($deletedTags) {
$this->itemsAdapter->deleteItems($deletedTags);
$this->itemsAdapter->saveDeferred($f(static::TAGS_PREFIX.$key, array_intersect_key($tagVersions, $tags), $items[$key]));
}
}

0 comments on commit fc9acad

Please sign in to comment.