Sleep and retry, if join fails
@@ -9,14 +9,20 @@ import (
"io/ioutil"
"net"
"net/http"
+ "time"
)
+const numAttempts int = 3
+const attemptInterval time.Duration = 5 * time.Second
+
// Join attempts to join the cluster at one of the addresses given in joinAddr.
// It walks through joinAddr in order, and sets the Raft address of the joining
// node as advAddr. It returns the endpoint successfully used to join the cluster.
func Join(joinAddr []string, advAddr string, skipVerify bool) (string, error) {
var err error
var j string
+
+ for i := 0; i < numAttempts; i++ {
for _, a := range joinAddr {
j, err = join(a, advAddr, skipVerify)
if err == nil {
@@ -24,6 +30,8 @@ func Join(joinAddr []string, advAddr string, skipVerify bool) (string, error) {
return j, nil
}
}
+ time.Sleep(attemptInterval)
+ }
return "", err
}
