Skip to content

Commit 8b8aced

Browse files
authored
Merge pull request #20 from Prizephitah/feature/waitcap-overflow-protection
Added protection against overflows in the wait time calculation.
2 parents cfbc47e + 37b27d1 commit 8b8aced

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Backoff.php

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public function getWaitTime($attempt)
329329
*/
330330
protected function cap($waitTime)
331331
{
332+
$waitTime = $waitTime < 0 ? PHP_INT_MAX : $waitTime;
332333
return is_int($this->getWaitCap())
333334
? min($this->getWaitCap(), $waitTime)
334335
: $waitTime;

tests/BackoffTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ public function testWaitCap()
151151
$this->assertEquals(5000, $b->getWaitTime(2));
152152
}
153153

154+
public function testWaitCapOverflow()
155+
{
156+
$b = new Backoff(1, new LinearStrategy(-1), 1000);
157+
158+
$this->assertEquals(1000, $b->getWaitTime(1));
159+
}
160+
154161
public function testWait()
155162
{
156163
$b = new Backoff(1, new LinearStrategy(50));

0 commit comments

Comments
 (0)