From 12302ba1bf741af0f607b6031923a31cd44d2ac5 Mon Sep 17 00:00:00 2001 From: Sudarsan Reddy Date: Fri, 1 Apr 2022 15:58:51 +0100 Subject: [PATCH] TUN-5973: Add backoff for non-recoverable errors as well Errors that are non-recoverable can lead to one of two things happening: 1. That connection lying dead and cloudflared not retrying to make that connection. 2. cloudflared resolving to a different edge addr to retry connection. We should subject these errors to a backoff as well. This will result in us introducing a backoff for 1. When we are going to let the connection become stale anyway and 2. When we are about to try a different edge addr. --- edgediscovery/edgediscovery.go | 3 ++- supervisor/tunnel.go | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/edgediscovery/edgediscovery.go b/edgediscovery/edgediscovery.go index 9f76b6fa..df9c42cc 100644 --- a/edgediscovery/edgediscovery.go +++ b/edgediscovery/edgediscovery.go @@ -114,7 +114,8 @@ func (ed *Edge) GetDifferentAddr(connIndex int) (*allregions.EdgeAddr, error) { // note: if oldAddr were not nil, it will become available on the next iteration return nil, errNoAddressesLeft } - log.Debug().Msg("edgediscovery - GetDifferentAddr: Giving connection its new address") + log.Debug().Msgf("edgediscovery - GetDifferentAddr: Giving connection its new address: %v from the address list: %v", + addr, ed.regions.AvailableAddrs()) return addr, nil } diff --git a/supervisor/tunnel.go b/supervisor/tunnel.go index 36fcbb5c..d6a588f4 100644 --- a/supervisor/tunnel.go +++ b/supervisor/tunnel.go @@ -171,17 +171,15 @@ func ServeTunnelLoop( protocolFallback.protocol, gracefulShutdownC, ) - if !recoverable { - return err - } - config.Observer.SendReconnect(connIndex) - - duration, ok := protocolFallback.GetMaxBackoffDuration(ctx) - if !ok { - return err + if recoverable { + duration, ok := protocolFallback.GetMaxBackoffDuration(ctx) + if !ok { + return err + } + config.Observer.SendReconnect(connIndex) + connLog.Logger().Info().Msgf("Retrying connection in up to %s seconds", duration) } - connLog.Logger().Info().Msgf("Retrying connection in up to %s seconds", duration) select { case <-ctx.Done(): @@ -189,6 +187,10 @@ func ServeTunnelLoop( case <-gracefulShutdownC: return nil case <-protocolFallback.BackoffTimer(): + if !recoverable { + return err + } + if !selectNextProtocol( connLog.Logger(), protocolFallback,