better retry
This commit is contained in:
@@ -399,6 +399,10 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
}()
|
||||
go func() {
|
||||
for range time.Tick(time.Second * 3) {
|
||||
if !remote.IsHealthy() {
|
||||
return
|
||||
}
|
||||
log.Printf("Pinging remote %s\n", host)
|
||||
err := remote.Ping()
|
||||
|
||||
for err != nil {
|
||||
|
||||
@@ -54,16 +54,25 @@ func NewPersistentConnection(address string) (*PersistentConnection, error) {
|
||||
}
|
||||
|
||||
func (m *PersistentConnection) Connect() error {
|
||||
if !m.Dead {
|
||||
fails := 0
|
||||
for {
|
||||
connection, err := net.Dial("tcp", m.address)
|
||||
if err != nil {
|
||||
log.Printf("Error connecting to %s: %v\n", m.address, err)
|
||||
m.Died <- true
|
||||
m.Dead = true
|
||||
return err
|
||||
fails++
|
||||
if fails > 15 {
|
||||
m.Died <- true
|
||||
m.Dead = true
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
m.Conn = connection
|
||||
break
|
||||
}
|
||||
m.Conn = connection
|
||||
time.Sleep(time.Millisecond * 300)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user