From 69dd503bf12be6b5042ad7ec615c9d102f728dee Mon Sep 17 00:00:00 2001 From: msaladna Date: Sun, 7 May 2017 19:28:24 -0400 Subject: [PATCH 1/3] Retry when rate-limit ceiling reached --- lib/AcmeClient.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib/AcmeClient.php diff --git a/lib/AcmeClient.php b/lib/AcmeClient.php old mode 100644 new mode 100755 index 7663508..6921ce9 --- a/lib/AcmeClient.php +++ b/lib/AcmeClient.php @@ -280,7 +280,7 @@ private function doPost($resource, array $payload) { $attempt++; if ($attempt > 3) { - throw new AcmeException("POST request to {$uri} failed, received too many badNonce errors."); + throw new AcmeException("POST request to {$uri} failed, received too many errors."); } $enc = new Base64UrlSafeEncoder(); @@ -312,6 +312,13 @@ private function doPost($resource, array $payload) { if ($info && isset($info->type) && ($info->type === "urn:acme:badNonce" or $info->type === "urn:acme:error:badNonce")) { continue; } + } else if ($response->getStatus() === 429) { + /** + * Hit rate limit + * @{link} https://letsencrypt.org/docs/rate-limits/ + */ + sleep(1); + continue; } } catch (Throwable $e) { throw new AcmeException("POST request to {$uri} failed: " . $e->getMessage(), null, $e); From 3eda1510ff7a3e50dc4dd6b68c1061926bef6b62 Mon Sep 17 00:00:00 2001 From: msaladna Date: Tue, 9 May 2017 23:41:51 -0400 Subject: [PATCH 2/3] fix expectedExceptionMessage annotation + include response code (400/429) --- lib/AcmeClient.php | 13 +++++++------ test/AcmeClientTest.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) mode change 100644 => 100755 test/AcmeClientTest.php diff --git a/lib/AcmeClient.php b/lib/AcmeClient.php index 6921ce9..00f81cc 100755 --- a/lib/AcmeClient.php +++ b/lib/AcmeClient.php @@ -275,14 +275,15 @@ private function doPost($resource, array $payload) { $uri = (yield $this->getResourceUri($resource)); $attempt = 0; + $statusCode = null; do { $attempt++; if ($attempt > 3) { - throw new AcmeException("POST request to {$uri} failed, received too many errors."); + throw new AcmeException("POST request to {$uri} failed, received too many errors (last code: ${statusCode})."); } - + $enc = new Base64UrlSafeEncoder(); $jws = new SimpleJWS([ "alg" => "RS256", @@ -305,14 +306,14 @@ private function doPost($resource, array $payload) { /** @var Response $response */ $response = (yield $this->http->request($request)); $this->saveNonce($response); - - if ($response->getStatus() === 400) { + $statusCode = $response->getStatus(); + if ($statusCode === 400) { $info = json_decode($response->getBody()); - if ($info && isset($info->type) && ($info->type === "urn:acme:badNonce" or $info->type === "urn:acme:error:badNonce")) { + if (!empty($info->type) && ($info->type === "urn:acme:badNonce" or $info->type === "urn:acme:error:badNonce")) { continue; } - } else if ($response->getStatus() === 429) { + } else if ($statusCode === 429) { /** * Hit rate limit * @{link} https://letsencrypt.org/docs/rate-limits/ diff --git a/test/AcmeClientTest.php b/test/AcmeClientTest.php old mode 100644 new mode 100755 index 8caa550..a10afa1 --- a/test/AcmeClientTest.php +++ b/test/AcmeClientTest.php @@ -200,7 +200,7 @@ public function failsWithInvalidDirectoryResponseButCorrectErrorResponse() { * @test * @depends boulderConfigured * @expectedException \Kelunik\Acme\AcmeException - * @expectedExceptionMessage too many badNonce errors + * @expectedExceptionMessage too many errors (last code: 400) */ public function failsWithTooManyBadNonceErrors() { $http = $this->getMockBuilder(HttpClient::class)->getMock(); From 5740a4aeebc4bc924328c388d1b1a159508a9396 Mon Sep 17 00:00:00 2001 From: msaladna Date: Wed, 10 May 2017 00:43:26 -0400 Subject: [PATCH 3/3] smb is possessed --- lib/AcmeClient.php | 2 +- test/AcmeClientTest.php | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 lib/AcmeClient.php mode change 100755 => 100644 test/AcmeClientTest.php diff --git a/lib/AcmeClient.php b/lib/AcmeClient.php old mode 100755 new mode 100644 index 00f81cc..a0e5a57 --- a/lib/AcmeClient.php +++ b/lib/AcmeClient.php @@ -283,7 +283,7 @@ private function doPost($resource, array $payload) { if ($attempt > 3) { throw new AcmeException("POST request to {$uri} failed, received too many errors (last code: ${statusCode})."); } - + $enc = new Base64UrlSafeEncoder(); $jws = new SimpleJWS([ "alg" => "RS256", diff --git a/test/AcmeClientTest.php b/test/AcmeClientTest.php old mode 100755 new mode 100644