Browse Source

graceful backoffs on connection retries

pull/239/head
Dan Ballard 1 year ago
parent
commit
7640fc1c0d
2 changed files with 9 additions and 4 deletions
  1. +8
    -3
      protocol/connections/connectionsmanager.go
  2. +1
    -1
      protocol/connections/peerserverconnection.go

+ 8
- 3
protocol/connections/connectionsmanager.go View File

@@ -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
}


+ 1
- 1
protocol/connections/peerserverconnection.go View File

@@ -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…
Cancel
Save