From db497e5d7e903c1fdfd412ec40e37b316cd97ada Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Thu, 18 Apr 2024 10:19:29 +0200 Subject: [PATCH 1/2] BUGFIX: Add exponential backoff when reading from Redis Fixes #3284 --- Neos.Cache/Classes/Backend/RedisBackend.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Neos.Cache/Classes/Backend/RedisBackend.php b/Neos.Cache/Classes/Backend/RedisBackend.php index ee0fb006c0..7b19872a44 100644 --- a/Neos.Cache/Classes/Backend/RedisBackend.php +++ b/Neos.Cache/Classes/Backend/RedisBackend.php @@ -170,7 +170,18 @@ private function calculateExpires(string $tag, int $lifetime): int */ public function get(string $entryIdentifier): string|bool { - return $this->uncompress($this->redis->get($this->getPrefixedIdentifier('entry:' . $entryIdentifier))); + $tries = 1; + do { + try { + return $this->uncompress($this->redis->get($this->getPrefixedIdentifier('entry:' . $entryIdentifier))); + } catch (\RedisException $exception) { + if ($tries > 8) { + throw $exception; + } + usleep($tries^2 * 100000); + $tries++; + } + } while (true); } /** From 1f63a30cd5b497ba85359742d6662dc08867f7db Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Mon, 29 Apr 2024 13:07:29 +0200 Subject: [PATCH 2/2] Use ** instead of ^ for exponentiation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🙈 --- Neos.Cache/Classes/Backend/RedisBackend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neos.Cache/Classes/Backend/RedisBackend.php b/Neos.Cache/Classes/Backend/RedisBackend.php index 7b19872a44..1229d7b381 100644 --- a/Neos.Cache/Classes/Backend/RedisBackend.php +++ b/Neos.Cache/Classes/Backend/RedisBackend.php @@ -178,7 +178,7 @@ public function get(string $entryIdentifier): string|bool if ($tries > 8) { throw $exception; } - usleep($tries^2 * 100000); + usleep($tries**2 * 100000); $tries++; } } while (true);