forked from Silverfish/proton-bridge
GODT-1468: Fix main windows status and add background context without retry.
This commit is contained in:
@ -30,20 +30,47 @@ var (
|
||||
)
|
||||
|
||||
func (m *manager) pingUntilSuccess() {
|
||||
if m.isPingOngoing() {
|
||||
logrus.Debug("Ping already ongoing")
|
||||
return
|
||||
}
|
||||
m.pingingStarted()
|
||||
defer m.pingingStopped()
|
||||
|
||||
attempt := 0
|
||||
for {
|
||||
err := m.testPing(context.Background())
|
||||
ctx := ContextWithoutRetry(context.Background())
|
||||
err := m.testPing(ctx)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
waitTime := getRetryConnectionSleep(attempt)
|
||||
attempt++
|
||||
logrus.WithError(err).WithField("attempt", attempt).WithField("wait", waitTime).Debug("Connection not available")
|
||||
logrus.WithError(err).WithField("attempt", attempt).WithField("wait", waitTime).Debug("Connection (still) not available")
|
||||
time.Sleep(waitTime)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *manager) isPingOngoing() bool {
|
||||
m.pingMutex.RLock()
|
||||
defer m.pingMutex.RUnlock()
|
||||
|
||||
return m.isPinging
|
||||
}
|
||||
|
||||
func (m *manager) pingingStarted() {
|
||||
m.pingMutex.Lock()
|
||||
defer m.pingMutex.Unlock()
|
||||
m.isPinging = true
|
||||
}
|
||||
|
||||
func (m *manager) pingingStopped() {
|
||||
m.pingMutex.Lock()
|
||||
defer m.pingMutex.Unlock()
|
||||
m.isPinging = false
|
||||
}
|
||||
|
||||
func getRetryConnectionSleep(idx int) time.Duration {
|
||||
if idx >= len(retryConnectionSleeps) {
|
||||
idx = len(retryConnectionSleeps) - 1
|
||||
|
||||
Reference in New Issue
Block a user