Fix backoff ticker

This commit is contained in:
Zoltán Papp 2024-07-11 15:46:07 +02:00
parent b5c9af9e9c
commit 807b830663

View File

@ -326,7 +326,7 @@ func (conn *Conn) reconnectLoopWithRetry() {
bo := backoff.WithContext(&backoff.ExponentialBackOff{ bo := backoff.WithContext(&backoff.ExponentialBackOff{
InitialInterval: 800 * time.Millisecond, InitialInterval: 800 * time.Millisecond,
RandomizationFactor: 0, RandomizationFactor: 0,
Multiplier: 1.7, Multiplier: 1.99,
MaxInterval: conn.config.Timeout * time.Second, MaxInterval: conn.config.Timeout * time.Second,
MaxElapsedTime: 0, MaxElapsedTime: 0,
Stop: backoff.Stop, Stop: backoff.Stop,
@ -336,10 +336,16 @@ func (conn *Conn) reconnectLoopWithRetry() {
ticker := backoff.NewTicker(bo) ticker := backoff.NewTicker(bo)
defer ticker.Stop() defer ticker.Stop()
<-ticker.C // consume the initial tick what is happening right after the ticker has been created
no := time.Now() no := time.Now()
for { for {
select { 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 // 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 // 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)) conn.log.Tracef("ticker timedout, relay state: %s, ice state: %s, elapsed time: %s", conn.statusRelay, conn.statusICE, time.Since(no))