From 807b8306630bc96bfdb56bce3f08e599217ee4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Thu, 11 Jul 2024 15:46:07 +0200 Subject: [PATCH] Fix backoff ticker --- client/internal/peer/conn.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 2f755a043..470a322be 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -326,7 +326,7 @@ func (conn *Conn) reconnectLoopWithRetry() { bo := backoff.WithContext(&backoff.ExponentialBackOff{ InitialInterval: 800 * time.Millisecond, RandomizationFactor: 0, - Multiplier: 1.7, + Multiplier: 1.99, MaxInterval: conn.config.Timeout * time.Second, MaxElapsedTime: 0, Stop: backoff.Stop, @@ -336,10 +336,16 @@ func (conn *Conn) reconnectLoopWithRetry() { ticker := backoff.NewTicker(bo) defer ticker.Stop() + <-ticker.C // consume the initial tick what is happening right after the ticker has been created + no := time.Now() for { select { - case <-ticker.C: + case t := <-ticker.C: + if t.IsZero() { + // in case if the ticker has been canceled by context then avoid the temporary loop + return + } // checks if there is peer connection is established via relay or ice and that it has a wireguard handshake and skip offer // todo check wg handshake conn.log.Tracef("ticker timedout, relay state: %s, ice state: %s, elapsed time: %s", conn.statusRelay, conn.statusICE, time.Since(no))