You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #22542 [Lock] Check TTL expiration in lock acquisition (jderusse)
This PR was squashed before being merged into the 3.4 branch (closes #22542).
Discussion
----------
[Lock] Check TTL expiration in lock acquisition
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #22452
| License | MIT
| Doc PR | NA
This PR improve lock acquisition by throwing exception when the TTL is expired during the lock process.
Commits
-------
f74ef35778 [Lock] Check TTL expiration in lock acquisition
@@ -102,10 +103,17 @@ public function putOffExpiration(Key $key, $ttl)
102
103
$successCount = 0;
103
104
$failureCount = 0;
104
105
$storesCount = count($this->stores);
106
+
$expireAt = microtime(true) + $ttl;
105
107
106
108
foreach ($this->storesas$store) {
107
109
try {
108
-
$store->putOffExpiration($key, $ttl);
110
+
if (0.0 >= $adjustedTtl = $expireAt - microtime(true)) {
111
+
$this->logger->warning('Stores took to long to put off the expiration of the "{resource}" lock.', array('resource' => $key, 'store' => $store, 'ttl' => $ttl));
112
+
$key->reduceLifetime(0);
113
+
break;
114
+
}
115
+
116
+
$store->putOffExpiration($key, $adjustedTtl);
109
117
++$successCount;
110
118
} catch (\Exception$e) {
111
119
$this->logger->warning('One store failed to put off the expiration of the "{resource}" lock.', array('resource' => $key, 'store' => $store, 'exception' => $e));
@@ -117,6 +125,10 @@ public function putOffExpiration(Key $key, $ttl)
117
125
}
118
126
}
119
127
128
+
if ($key->isExpired()) {
129
+
thrownewLockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $key));
130
+
}
131
+
120
132
if ($this->strategy->isMet($successCount, $storesCount)) {
0 commit comments