forked from TrueCloudLab/lego
retry get nonce few times before return error
This commit is contained in:
parent
f32c8a55e7
commit
3a426a1382
1 changed files with 17 additions and 6 deletions
23
acme/jws.go
23
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
|
||||
|
|
Loading…
Reference in a new issue