|
6 | 6 | use Aws\Retry\QuotaManager; |
7 | 7 | use Aws\Retry\RateLimiter; |
8 | 8 | use Aws\Retry\RetryHelperTrait; |
| 9 | +use Exception; |
9 | 10 | use GuzzleHttp\Exception\RequestException; |
10 | 11 | use GuzzleHttp\Promise; |
11 | 12 | use Psr\Http\Message\RequestInterface; |
@@ -200,7 +201,7 @@ public function __invoke(CommandInterface $cmd, RequestInterface $req) |
200 | 201 | $value->prependMonitoringEvent($event); |
201 | 202 | } |
202 | 203 | } |
203 | | - if ($value instanceof \Exception || $value instanceof \Throwable) { |
| 204 | + if ($value instanceof Exception || $value instanceof \Throwable) { |
204 | 205 | if (!$decider($attempts, $cmd, $value)) { |
205 | 206 | return Promise\Create::rejectionFor( |
206 | 207 | $this->bindStatsToReturn($value, $requestStats) |
@@ -245,7 +246,14 @@ public function __invoke(CommandInterface $cmd, RequestInterface $req) |
245 | 246 | */ |
246 | 247 | public function exponentialDelayWithJitter($attempts) |
247 | 248 | { |
248 | | - $rand = mt_rand() / mt_getrandmax(); |
| 249 | + $max = mt_getrandmax(); |
| 250 | + try { |
| 251 | + $rand = random_int(0, $max) / $max; |
| 252 | + } catch (Exception $_) { |
| 253 | + // fallback to prevent failing |
| 254 | + $rand = mt_rand(0, $max) / $max; |
| 255 | + } |
| 256 | + |
249 | 257 | return min(1000 * $rand * pow(2, $attempts) , $this->maxBackoff); |
250 | 258 | } |
251 | 259 |
|
@@ -287,7 +295,7 @@ private static function isRetryable( |
287 | 295 | } |
288 | 296 | } |
289 | 297 |
|
290 | | - if ($result instanceof \Exception || $result instanceof \Throwable) { |
| 298 | + if ($result instanceof Exception || $result instanceof \Throwable) { |
291 | 299 | $isError = true; |
292 | 300 | } else { |
293 | 301 | $isError = false; |
|
0 commit comments