8000 bug #27318 [Cache] memcache connect should not add duplicate entries … · symfony/symfony@9a077ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a077ca

Browse files
bug #27318 [Cache] memcache connect should not add duplicate entries on sequential calls (Aleksey Prilipko)
This PR was submitted for the 3.3 branch but it was merged into the 3.4 branch instead (closes #27318). Discussion ---------- [Cache] memcache connect should not add duplicate entries on sequential calls | Q | A | ------------- | --- | Branch? | 3.4 (be careful when merging) | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | #27299 | License | MIT MemcachedCache::createConnection adds server to list of servers on every call. But resets this list only when it is not empty and does not match configured list. This leads to follow: after first call list contains correct entry. After second it has server entry twice. After third it clears list and set it with correct value. With combination of libmemcached bug (segfault on adding server after reset nonempty list) it makes impossible to use MemcachedCache::createConnection to create persistent connections. Commits ------- af06990 bug #27299 [Cache] memcache connect should not add duplicate entries on sequential calls
2 parents 13be093 + af06990 commit 9a077ca

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public function createSimpleCache($defaultLifetime = 0)
4545
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
4646
}
4747

48+
public function testCreatePersistentConnectionShouldNotDupServerList()
49+
{
50+
$instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('persistent_id' => 'persistent'));
51+
$this->assertCount(1, $instance->getServerList());
52+
53+
$instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('persistent_id' => 'persistent'));
54+
$this->assertCount(1, $instance->getServerList());
55+
}
56+
4857
public function testOptions()
4958
{
5059
$client = MemcachedCache::createConnection(array(), array(

src/Symfony/Component/Cache/Traits/MemcachedTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ public static function createConnection($servers, array $options = array())
169169
}
170170

171171
if ($oldServers !== $newServers) {
172-
// before resetting, ensure $servers is valid
173-
$client->addServers($servers);
174172
$client->resetServerList();
173+
$client->addServers($servers);
175174
}
175+
} else {
176+
$client->addServers($servers);
176177
}
177-
$client->addServers($servers);
178178

179179
if (null !== $username || null !== $password) {
180180
if (!method_exists($client, 'setSaslAuthData')) {

0 commit comments

Comments
 (0)
0