diff --git a/.changes/nextrelease/retry_curl35.json b/.changes/nextrelease/retry_curl35.json new file mode 100644 index 0000000000..309440917c --- /dev/null +++ b/.changes/nextrelease/retry_curl35.json @@ -0,0 +1,7 @@ +[ + { + "type": "enhancement", + "category": "", + "description": "Enables retries of the CURLE_SSL_CONNECT_ERROR (35) failure." + } +] diff --git a/src/RetryMiddleware.php b/src/RetryMiddleware.php index 4fa81e9871..019fe1dc74 100644 --- a/src/RetryMiddleware.php +++ b/src/RetryMiddleware.php @@ -80,6 +80,7 @@ public static function createDefaultDecider( ) { $retryCurlErrors = []; if (extension_loaded('curl')) { + $retryCurlErrors[CURLE_SSL_CONNECT_ERROR] = true; $retryCurlErrors[CURLE_RECV_ERROR] = true; } diff --git a/tests/RetryMiddlewareTest.php b/tests/RetryMiddlewareTest.php index 9f64b0e35a..7d72f1b1fa 100644 --- a/tests/RetryMiddlewareTest.php +++ b/tests/RetryMiddlewareTest.php @@ -84,7 +84,12 @@ public function testDeciderIgnoresPHPError() } } - public function testDeciderRetriesWhenCurlErrorCodeMatches() + /** + * @param int $curlErrorCode + * @param bool $expected + * @dataProvider curlErrorCodesProvider + */ + public function testDeciderRetriesWhenCurlErrorCodeMatches($curlErrorCode, $expected) { if (!extension_loaded('curl')) { $this->markTestSkipped('Test skipped on no cURL extension'); @@ -99,11 +104,11 @@ public function testDeciderRetriesWhenCurlErrorCodeMatches() $request, null, null, - ['errno' => CURLE_RECV_ERROR] + ['errno' => $curlErrorCode] ); } elseif ($version === 5) { $previous = new RequestException( - 'cURL error ' . CURLE_RECV_ERROR . ': test', + 'cURL error ' . $curlErrorCode . ': test', new \GuzzleHttp\Message\Request('GET', 'http://www.example.com') ); } @@ -113,7 +118,16 @@ public function testDeciderRetriesWhenCurlErrorCodeMatches() ['connection_error' => false], $previous ); - $this->assertTrue($decider(0, $command, $request, null, $err)); + $this->assertEquals($expected, $decider(0, $command, $request, null, $err)); + } + + public static function curlErrorCodesProvider() + { + return [ + 'Error 35 should retry' => [CURLE_SSL_CONNECT_ERROR, true], + 'Error 56 should retry' => [CURLE_RECV_ERROR, true], + 'Error 0 should not retry' => [CURLE_OK, false], + ]; } public function testDeciderRetriesForCustomCurlErrors()