Skip to content

Commit f9bee01

Browse files
committed
MC-32426: Change timeout lockup
1 parent a73532a commit f9bee01

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/internal/Magento/Framework/Cache/LockGuardedCacheLoader.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,34 @@ class LockGuardedCacheLoader
4848
private $loadTimeout;
4949

5050
/**
51-
* LockGuardedCacheLoader constructor.
51+
* Minimal delay timeout in ms.
52+
* Delay will be applied as rand($minimalDelayTimeout, $delayTimeout)
53+
* in order to desynchronize multiple clients trying
54+
* to acquire the lock for the same resource at the same time
55+
*
56+
* @var int
57+
*/
58+
private $minimalDelayTimeout;
59+
60+
/**
5261
* @param LockManagerInterface $locker
5362
* @param int $lockTimeout
5463
* @param int $delayTimeout
5564
* @param int $loadTimeout
65+
* @param int $minimalDelayTimeout
5666
*/
5767
public function __construct(
5868
LockManagerInterface $locker,
5969
int $lockTimeout = 10000,
6070
int $delayTimeout = 20,
61-
int $loadTimeout = 10000
71+
int $loadTimeout = 10000,
72+
int $minimalDelayTimeout = 5
6273
) {
6374
$this->locker = $locker;
6475
$this->lockTimeout = $lockTimeout;
6576
$this->delayTimeout = $delayTimeout;
6677
$this->loadTimeout = $loadTimeout;
78+
$this->minimalDelayTimeout = $minimalDelayTimeout;
6779
}
6880

6981
/**
@@ -100,7 +112,8 @@ public function lockedLoadData(
100112
}
101113

102114
if ($cachedData === false) {
103-
usleep($this->delayTimeout * 1000);
115+
$lookupTimeout = rand($this->minimalDelayTimeout, $this->delayTimeout);
116+
usleep($lookupTimeout * 1000);
104117
$cachedData = $dataLoader();
105118
}
106119
}

0 commit comments

Comments
 (0)