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
13
acme/jws.go
13
acme/jws.go
|
@ -11,8 +11,12 @@ import (
|
||||||
|
|
||||||
"gopkg.in/square/go-jose.v1"
|
"gopkg.in/square/go-jose.v1"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const TRY_COUNT = 10
|
||||||
|
const RETRY_PAUSE = time.Second
|
||||||
|
|
||||||
type jws struct {
|
type jws struct {
|
||||||
directoryURL string
|
directoryURL string
|
||||||
privKey crypto.PrivateKey
|
privKey crypto.PrivateKey
|
||||||
|
@ -97,14 +101,21 @@ func (j *jws) getNonce() error {
|
||||||
func (j *jws) Nonce() (string, error) {
|
func (j *jws) Nonce() (string, error) {
|
||||||
nonce := ""
|
nonce := ""
|
||||||
if len(j.nonces) == 0 {
|
if len(j.nonces) == 0 {
|
||||||
|
for i := 0; i < TRY_COUNT; i++ {
|
||||||
err := j.getNonce()
|
err := j.getNonce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nonce, err
|
return nonce, err
|
||||||
}
|
}
|
||||||
|
if len(j.nonces) != 0 {
|
||||||
|
// get nonce ok and can continue
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(RETRY_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(j.nonces) == 0 {
|
if len(j.nonces) == 0 {
|
||||||
return "", errors.New("Can't get nonce")
|
return "", errors.New("Can't get nonce")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1]
|
nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1]
|
||||||
return nonce, nil
|
return nonce, nil
|
||||||
|
|
Loading…
Reference in a new issue