bug #33703 [Cache] fail gracefully when locking is not supported (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

[Cache] fail gracefully when locking is not supported

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33392
| License       | MIT
| Doc PR        | -

Commits
-------

93485190f9 [Cache] fail gracefully when locking is not supported
This commit is contained in:
Fabien Potencier 2019-09-26 10:04:46 +02:00
commit 0222ea5df9

View File

@ -90,8 +90,10 @@ final class LockRegistry
while (true) {
try {
// race to get the lock in non-blocking mode
if (flock($lock, LOCK_EX | LOCK_NB)) {
$logger && $logger->info('Lock acquired, now computing item "{key}"', ['key' => $item->getKey()]);
$locked = flock($lock, LOCK_EX | LOCK_NB, $wouldBlock);
if ($locked || !$wouldBlock) {
$logger && $logger->info(sprintf('Lock %s, now computing item "{key}"', $locked ? 'acquired' : 'not supported'), ['key' => $item->getKey()]);
self::$lockedFiles[$key] = true;
$value = $callback($item, $save);