mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-05-29 11:10:32 +00:00
Merge pull request #103 from cloudflare/jkroll/backoff
Add exponential backoff to the Red October client
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user