From 10b019225553a4b73481b04fe6f8d40bcc8270c7 Mon Sep 17 00:00:00 2001 From: xenolf Date: Sun, 18 Oct 2015 17:27:59 +0200 Subject: [PATCH] Fix goroutine leak. Fixes #10 Tired coding is bad for you, mkay? --- acme/client.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/acme/client.go b/acme/client.go index dfbacb4e..58cb74f6 100644 --- a/acme/client.go +++ b/acme/client.go @@ -305,6 +305,9 @@ func (c *Client) requestCertificates(challenges []*authorizationResource) ([]Cer } } + close(resc) + close(errc) + return certs, nil } @@ -358,20 +361,23 @@ func (c *Client) requestCertificate(authz *authorizationResource, result chan Ce if len(cert) > 0 { cerRes.CertStableURL = resp.Header.Get("Content-Location") cerRes.Certificate = pemEncode(derCertificateBytes(cert)) + logger().Printf("[%s] Server responded with a certificate.", authz.Domain) result <- cerRes - } else { - // The certificate was granted but is not yet issued. - // Check retry-after and loop. - ra := resp.Header.Get("Retry-After") - retryAfter, err := strconv.Atoi(ra) - if err != nil { - errc <- err - return - } - - logger().Printf("[%s] Server responded with status 202. Respecting retry-after of: %d", authz.Domain, retryAfter) - time.Sleep(time.Duration(retryAfter) * time.Millisecond) + return } + + // The certificate was granted but is not yet issued. + // Check retry-after and loop. + ra := resp.Header.Get("Retry-After") + retryAfter, err := strconv.Atoi(ra) + if err != nil { + errc <- err + return + } + + logger().Printf("[%s] Server responded with status 202. Respecting retry-after of: %d", authz.Domain, retryAfter) + time.Sleep(time.Duration(retryAfter) * time.Second) + break default: logger().Fatalf("[%s] The server returned an unexpected status code %d.", authz.Domain, resp.StatusCode)