Skip to content

Commit 6e7fe3e

Browse files
bug #57933 [Messenger] Prevent waiting time to overflow when using long delays (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [Messenger] Prevent waiting time to overflow when using long delays | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57779 | License | MIT There are two places where integers can overflow, thus the limiting to `PHP_INT_MAX`. Commits ------- 9609e23 [Messenger] Prevent waiting time to overflow when using long delays
2 parents 5abfba2 + 9609e23 commit 6e7fe3e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Symfony/Component/Messenger/Retry/MultiplierRetryStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ public function getWaitingTime(Envelope $message, ?\Throwable $throwable = null)
8383
$delay = $this->delayMilliseconds * $this->multiplier ** $retries;
8484

8585
if ($this->jitter > 0) {
86-
$randomness = (int) ($delay * $this->jitter);
86+
$randomness = (int) min(\PHP_INT_MAX, $delay * $this->jitter);
8787
$delay += random_int(-$randomness, +$randomness);
8888
}
8989

9090
if ($delay > $this->maxDelayMilliseconds && 0 !== $this->maxDelayMilliseconds) {
9191
return $this->maxDelayMilliseconds;
9292
}
9393

94-
return (int) ceil($delay);
94+
return (int) min(\PHP_INT_MAX, ceil($delay));
9595
}
9696
}

src/Symfony/Component/Messenger/Tests/Retry/MultiplierRetryStrategyTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public function testGetWaitTime(int $delay, float $multiplier, int $maxDelay, in
6060
$this->assertSame($expectedDelay, $strategy->getWaitingTime($envelope));
6161
}
6262

63+
public function testGetWaitTimeWithOverflowingDelay()
64+
{
65+
$strategy = new MultiplierRetryStrategy(512, \PHP_INT_MAX, 2, 0, 1);
66+
$envelope = new Envelope(new \stdClass(), [new RedeliveryStamp(10)]);
67+
68+
$this->assertSame(\PHP_INT_MAX, $strategy->getWaitingTime($envelope));
69+
}
70+
6371
public static function getWaitTimeTests(): iterable
6472
{
6573
// delay, multiplier, maxDelay, retries, expectedDelay

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy