diff --git a/client/client.go b/client/client.go index abb18f3..c12566f 100644 --- a/client/client.go +++ b/client/client.go @@ -8,8 +8,11 @@ import ( "errors" "fmt" "io/ioutil" + "log" "net/http" + "time" + backoff "github.com/cloudflare/cfssl/transport/core" "github.com/cloudflare/redoctober/core" ) @@ -59,9 +62,17 @@ func (c *RemoteServer) getURL(path string) string { func (c *RemoteServer) doAction(action string, req []byte) ([]byte, error) { buf := bytes.NewBuffer(req) url := c.getURL("/" + action) - resp, err := c.client.Post(url, "application/json", buf) - if err != nil { - return nil, err + b := backoff.Backoff{} + var resp *http.Response + var err error + for { + resp, err = c.client.Post(url, "application/json", buf) + if err == nil { + break + } + delay := b.Duration() + log.Printf("Request to server failed. Will try again in %s", delay) + <-time.After(delay) } body, err := ioutil.ReadAll(resp.Body)