Skip to content

Commit 15d5aac

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

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class LockGuardedCacheLoader
4949

5050
/**
5151
* 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
5552
*
5653
* @var int
5754
*/
@@ -112,8 +109,7 @@ public function lockedLoadData(
112109
}
113110

114111
if ($cachedData === false) {
115-
$lookupTimeout = rand($this->minimalDelayTimeout, $this->delayTimeout);
116-
usleep($lookupTimeout * 1000);
112+
usleep($this->getLookupTimeout() * 1000);
117113
$cachedData = $dataLoader();
118114
}
119115
}
@@ -131,7 +127,7 @@ public function lockedLoadData(
131127
public function lockedCleanData(string $lockName, callable $dataCleaner)
132128
{
133129
while ($this->locker->isLocked($lockName)) {
134-
usleep($this->delayTimeout * 1000);
130+
usleep($this->getLookupTimeout() * 1000);
135131
}
136132
try {
137133
if ($this->locker->lock($lockName, $this->lockTimeout / 1000)) {
@@ -141,4 +137,18 @@ public function lockedCleanData(string $lockName, callable $dataCleaner)
141137
$this->locker->unlock($lockName);
142138
}
143139
}
140+
141+
/**
142+
* Delay will be applied as rand($minimalDelayTimeout, $delayTimeout).
143+
* This helps to desynchronize multiple clients trying
144+
* to acquire the lock for the same resource at the same time
145+
*
146+
* @return int
147+
*/
148+
private function getLookupTimeout()
149+
{
150+
$lookupTimeout = rand($this->minimalDelayTimeout, $this->delayTimeout);
151+
152+
return $lookupTimeout;
153+
}
144154
}

0 commit comments

Comments
 (0)