Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43ab20e

Browse files
bug #39476 [Lock] Prevent store exception break combined store (dzubchik)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Lock] Prevent store exception break combined store | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #39470 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Handle exception to preserve expected behavior - one or multiple stores could be unreachable in a moment and combined store will handle this according to strategy. Commits ------- 0daff35 [Lock] Prevent store exception break combined store
2 parents 3ebcc28 + 0daff35 commit 43ab20e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/Symfony/Component/Lock/Store/CombinedStore.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ public function exists(Key $key)
171171
$storesCount = \count($this->stores);
172172

173173
foreach ($this->stores as $store) {
174-
if ($store->exists($key)) {
175-
++$successCount;
176-
} else {
174+
try {
175+
if ($store->exists($key)) {
176+
++$successCount;
177+
} else {
178+
++$failureCount;
179+
}
180+
} catch (\Exception $e) {
181+
$this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
177182
++$failureCount;
178183
}
179184

src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,29 @@ public function testDeleteDontStopOnFailure()
351351

352352
$this->store->delete($key);
353353
}
354+
355+
public function testExistsDontStopOnFailure()
356+
{
357+
$key = new Key(uniqid(__METHOD__, true));
358+
359+
$this->strategy
360+
->expects($this->any())
361+
->method('canBeMet')
362+
->willReturn(true);
363+
$this->strategy
364+
->expects($this->any())
365+
->method('isMet')
366+
->willReturn(false);
367+
$this->store1
368+
->expects($this->once())
369+
->method('exists')
370+
->willThrowException(new \Exception());
371+
$this->store2
372+
->expects($this->once())
373+
->method('exists')
374+
->with($key)
375+
->willReturn(false);
376+
377+
$this->assertFalse($this->store->exists($key));
378+
}
354379
}

0 commit comments

Comments
 (0)