modify route

This commit is contained in:
zhouyuyan
2018-01-18 09:17:48 +08:00
parent 1339a04b28
commit 819b4725f2

View File

@@ -342,12 +342,31 @@ func (b *Broker) ConnectToRouters() {
func (b *Broker) connectRouter(url, remoteID string) { func (b *Broker) connectRouter(url, remoteID string) {
var conn net.Conn var conn net.Conn
var err error var err error
var timeDelay time.Duration = 0
retryTimes := 0
max := 32 * time.Second
for { for {
conn, err = net.Dial("tcp", url) conn, err = net.Dial("tcp", url)
if err != nil { if err != nil {
log.Error("Error trying to connect to route: ", err) log.Error("Error trying to connect to route: ", err)
if retryTimes > 50 {
return
}
log.Debug("Connect to route timeout ,retry...") log.Debug("Connect to route timeout ,retry...")
time.Sleep(5 * time.Second)
if 0 == timeDelay {
timeDelay = 1 * time.Second
} else {
timeDelay *= 2
}
if timeDelay > max {
timeDelay = max
}
time.Sleep(timeDelay)
retryTimes++
continue continue
} }
break break