Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: retry CURLE_SSL_CONNECT_ERROR failures #2972

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/retry_curl35.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Enables retries of the CURLE_SSL_CONNECT_ERROR (35) failure."
}
]
1 change: 1 addition & 0 deletions src/RetryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static function createDefaultDecider(
) {
$retryCurlErrors = [];
if (extension_loaded('curl')) {
$retryCurlErrors[CURLE_SSL_CONNECT_ERROR] = true;
$retryCurlErrors[CURLE_RECV_ERROR] = true;
}

Expand Down
22 changes: 18 additions & 4 deletions tests/RetryMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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')
);
}
Expand All @@ -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()
Expand Down