Skip to content
Snippets Groups Projects
Commit ab5c9bdd authored by Manish R Jain's avatar Manish R Jain
Browse files

Retry on connection refused

parent 845d46e7
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ package conn
import (
"net"
"net/rpc"
"strings"
"time"
"github.com/dgraph-io/dgraph/x"
)
......@@ -28,7 +30,24 @@ func NewPool(addr string, maxCap int) *Pool {
}
func (p *Pool) dialNew() (*rpc.Client, error) {
nconn, err := net.Dial("tcp", p.addr)
d := &net.Dialer{
Timeout: 3 * time.Minute,
}
var nconn net.Conn
var err error
for i := 0; i < 10; i++ {
nconn, err = d.Dial("tcp", p.addr)
if err == nil {
break
}
if !strings.Contains(err.Error(), "refused") {
break
}
glog.WithField("error", err).WithField("addr", p.addr).
Info("Retrying connection...")
time.Sleep(10 * time.Second)
}
if err != nil {
return nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment