TUN-3948: Log error when retrying connection

This commit is contained in:
Nuno Diegues 2021-02-22 15:30:27 +00:00
parent 4e33281337
commit e9c2afec56
1 changed files with 10 additions and 8 deletions

View File

@ -244,7 +244,7 @@ func selectNextProtocol(
// on error returns a flag indicating if error can be retried // on error returns a flag indicating if error can be retried
func ServeTunnel( func ServeTunnel(
ctx context.Context, ctx context.Context,
connLong *zerolog.Logger, connLog *zerolog.Logger,
credentialManager *reconnectCredentialManager, credentialManager *reconnectCredentialManager,
config *TunnelConfig, config *TunnelConfig,
addr *net.TCPAddr, addr *net.TCPAddr,
@ -273,6 +273,7 @@ func ServeTunnel(
edgeConn, err := edgediscovery.DialEdge(ctx, dialTimeout, config.EdgeTLSConfigs[protocol], addr) edgeConn, err := edgediscovery.DialEdge(ctx, dialTimeout, config.EdgeTLSConfigs[protocol], addr)
if err != nil { if err != nil {
connLog.Err(err).Msg("Unable to establish connection with Cloudflare edge")
return err, true return err, true
} }
connectedFuse := &connectedFuse{ connectedFuse := &connectedFuse{
@ -284,7 +285,7 @@ func ServeTunnel(
connOptions := config.ConnectionOptions(edgeConn.LocalAddr().String(), uint8(backoff.retries)) connOptions := config.ConnectionOptions(edgeConn.LocalAddr().String(), uint8(backoff.retries))
err = ServeHTTP2( err = ServeHTTP2(
ctx, ctx,
connLong, connLog,
config, config,
edgeConn, edgeConn,
connOptions, connOptions,
@ -296,7 +297,7 @@ func ServeTunnel(
} else { } else {
err = ServeH2mux( err = ServeH2mux(
ctx, ctx,
connLong, connLog,
credentialManager, credentialManager,
config, config,
edgeConn, edgeConn,
@ -311,28 +312,29 @@ func ServeTunnel(
if err != nil { if err != nil {
switch err := err.(type) { switch err := err.(type) {
case connection.DupConnRegisterTunnelError: case connection.DupConnRegisterTunnelError:
connLog.Err(err).Msg("Unable to establish connection.")
// don't retry this connection anymore, let supervisor pick a new address // don't retry this connection anymore, let supervisor pick a new address
return err, false return err, false
case connection.ServerRegisterTunnelError: case connection.ServerRegisterTunnelError:
connLong.Err(err).Msg("Register tunnel error from server side") connLog.Err(err).Msg("Register tunnel error from server side")
// Don't send registration error return from server to Sentry. They are // Don't send registration error return from server to Sentry. They are
// logged on server side // logged on server side
if incidents := config.IncidentLookup.ActiveIncidents(); len(incidents) > 0 { if incidents := config.IncidentLookup.ActiveIncidents(); len(incidents) > 0 {
connLong.Error().Msg(activeIncidentsMsg(incidents)) connLog.Error().Msg(activeIncidentsMsg(incidents))
} }
return err.Cause, !err.Permanent return err.Cause, !err.Permanent
case ReconnectSignal: case ReconnectSignal:
connLong.Info(). connLog.Info().
Uint8(connection.LogFieldConnIndex, connIndex). Uint8(connection.LogFieldConnIndex, connIndex).
Msgf("Restarting connection due to reconnect signal in %s", err.Delay) Msgf("Restarting connection due to reconnect signal in %s", err.Delay)
err.DelayBeforeReconnect() err.DelayBeforeReconnect()
return err, true return err, true
default: default:
if err == context.Canceled { if err == context.Canceled {
connLong.Debug().Err(err).Msgf("Serve tunnel error") connLog.Debug().Err(err).Msgf("Serve tunnel error")
return err, false return err, false
} }
connLong.Err(err).Msgf("Serve tunnel error") connLog.Err(err).Msgf("Serve tunnel error")
_, permanent := err.(unrecoverableError) _, permanent := err.(unrecoverableError)
return err, !permanent return err, !permanent
} }