From 54422ab22699dc619f76a1e9d9f053667d9b4e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20K=C3=A4stel?= Date: Mon, 25 Jun 2018 23:22:42 +0200 Subject: [PATCH] Order polling wait (#581) --- acme/client.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/acme/client.go b/acme/client.go index ebfd11a2..1f8f942f 100644 --- a/acme/client.go +++ b/acme/client.go @@ -708,25 +708,30 @@ func (c *Client) requestCertificateForCsr(order orderResource, bundle bool, csr } } - maxChecks := 1000 - for i := 0; i < maxChecks; i++ { - _, err := getJSON(order.URL, &retOrder) - if err != nil { - return nil, err - } - done, err := c.checkCertResponse(retOrder, &certRes, bundle) - if err != nil { - return nil, err - } - if done { - break - } - if i == maxChecks-1 { - return nil, fmt.Errorf("polled for certificate %d times; giving up", i) + stopTimer := time.NewTimer(30 * time.Second) + defer stopTimer.Stop() + retryTick := time.NewTicker(500 * time.Millisecond) + defer retryTick.Stop() + + for { + select { + case <-stopTimer.C: + return nil, errors.New("certificate polling timed out") + case <-retryTick.C: + _, err := getJSON(order.URL, &retOrder) + if err != nil { + return nil, err + } + + done, err := c.checkCertResponse(retOrder, &certRes, bundle) + if err != nil { + return nil, err + } + if done { + return &certRes, nil + } } } - - return &certRes, nil } // checkCertResponse checks to see if the certificate is ready and a link is contained in the