better retry
This commit is contained in:
@@ -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