Skip to content

Commit 12302ba

Browse files
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.
1 parent 317a7ea commit 12302ba

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

edgediscovery/edgediscovery.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func (ed *Edge) GetDifferentAddr(connIndex int) (*allregions.EdgeAddr, error) {
114114
// note: if oldAddr were not nil, it will become available on the next iteration
115115
return nil, errNoAddressesLeft
116116
}
117-
log.Debug().Msg("edgediscovery - GetDifferentAddr: Giving connection its new address")
117+
log.Debug().Msgf("edgediscovery - GetDifferentAddr: Giving connection its new address: %v from the address list: %v",
118+
addr, ed.regions.AvailableAddrs())
118119
return addr, nil
119120
}
120121

supervisor/tunnel.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,26 @@ func ServeTunnelLoop(
171171
protocolFallback.protocol,
172172
gracefulShutdownC,
173173
)
174-
if !recoverable {
175-
return err
176-
}
177-
178-
config.Observer.SendReconnect(connIndex)
179174

180-
duration, ok := protocolFallback.GetMaxBackoffDuration(ctx)
181-
if !ok {
182-
return err
175+
if recoverable {
176+
duration, ok := protocolFallback.GetMaxBackoffDuration(ctx)
177+
if !ok {
178+
return err
179+
}
180+
config.Observer.SendReconnect(connIndex)
181+
connLog.Logger().Info().Msgf("Retrying connection in up to %s seconds", duration)
183182
}
184-
connLog.Logger().Info().Msgf("Retrying connection in up to %s seconds", duration)
185183

186184
select {
187185
case <-ctx.Done():
188186
return ctx.Err()
189187
case <-gracefulShutdownC:
190188
return nil
191189
case <-protocolFallback.BackoffTimer():
190+
if !recoverable {
191+
return err
192+
}
193+
192194
if !selectNextProtocol(
193195
connLog.Logger(),
194196
protocolFallback,

0 commit comments

Comments
 (0)