From 3a426a1382d157ccc75bc801edf9d5f33c2a4c69 Mon Sep 17 00:00:00 2001 From: Rekby Date: Mon, 11 Apr 2016 07:22:00 +0300 Subject: [PATCH] retry get nonce few times before return error --- acme/jws.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/acme/jws.go b/acme/jws.go index dbb32ccf..453b791c 100644 --- a/acme/jws.go +++ b/acme/jws.go @@ -11,8 +11,12 @@ import ( "gopkg.in/square/go-jose.v1" "errors" + "time" ) +const TRY_COUNT = 10 +const RETRY_PAUSE = time.Second + type jws struct { directoryURL string privKey crypto.PrivateKey @@ -97,14 +101,21 @@ func (j *jws) getNonce() error { func (j *jws) Nonce() (string, error) { nonce := "" if len(j.nonces) == 0 { - err := j.getNonce() - if err != nil { - return nonce, err - } - if len(j.nonces) == 0 { - return "", errors.New("Can't get nonce") + for i := 0; i < TRY_COUNT; i++ { + err := j.getNonce() + if err != nil { + return nonce, err + } + if len(j.nonces) != 0 { + // get nonce ok and can continue + break + } + time.Sleep(RETRY_PAUSE); } } + if len(j.nonces) == 0 { + return "", errors.New("Can't get nonce") + } nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1] return nonce, nil