forked from cwtch.im/cwtch
graceful backoffs on connection retries
This commit is contained in:
parent
fca4fe17eb
commit
7640fc1c0d
|
@ -99,7 +99,9 @@ func (m *Manager) GetPeerServerConnectionForOnion(host string) (psc *PeerServerC
|
|||
|
||||
// AttemptReconnections repeatedly attempts to reconnect with failed peers and servers.
|
||||
func (m *Manager) AttemptReconnections() {
|
||||
timeout := time.Duration(0) // first pass right away
|
||||
maxTimeout := time.Minute * 5
|
||||
// nearly instant first run, next few runs will prolly be too quick to have any FAILED and will gracefully slow to MAX after that
|
||||
timeout := time.Millisecond * 500
|
||||
|
||||
for {
|
||||
select {
|
||||
|
@ -120,8 +122,11 @@ func (m *Manager) AttemptReconnections() {
|
|||
}
|
||||
m.lock.Unlock()
|
||||
|
||||
// Launch Another Run In 30 Seconds
|
||||
timeout = time.Duration(30 * time.Second)
|
||||
if timeout < maxTimeout {
|
||||
timeout = timeout * 2
|
||||
} else {
|
||||
timeout = maxTimeout
|
||||
}
|
||||
case <-m.breakChannel:
|
||||
return
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ func (psc *PeerServerConnection) SendGroupMessage(gm *protocol.GroupMessage) err
|
|||
|
||||
errCount := 0
|
||||
for errCount < 5 {
|
||||
time.Sleep(time.Second * 1)
|
||||
time.Sleep(time.Second * time.Duration(errCount+1)) // back off retry
|
||||
err = psc.connection.Do(func() error {
|
||||
channel := psc.connection.Channel("im.cwtch.server.send", channels.Outbound)
|
||||
if channel == nil {
|
||||
|
|
Loading…
Reference in New Issue