TUN-3169: Move on to the next address when edge returns duplicate connection. There's no point in trying to connect to the same address since it will be hashed to the same metal.

Improve logging of errors from serve tunnel loop, hide useless context cancelled error.
This commit is contained in:
Igor Postelnik 2020-07-07 16:35:44 -05:00
parent f7ff41f1dc
commit ac3638f6b1
1 changed files with 17 additions and 13 deletions

View File

@ -105,7 +105,7 @@ type dupConnRegisterTunnelError struct{}
var errDuplicationConnection = &dupConnRegisterTunnelError{} var errDuplicationConnection = &dupConnRegisterTunnelError{}
func (e dupConnRegisterTunnelError) Error() string { func (e dupConnRegisterTunnelError) Error() string {
return "already connected to this server" return "already connected to this server, trying another address"
} }
type muxerShutdownError struct{} type muxerShutdownError struct{}
@ -376,29 +376,33 @@ func ServeTunnel(
err = errGroup.Wait() err = errGroup.Wait()
if err != nil { if err != nil {
switch castedErr := err.(type) { switch err := err.(type) {
case dupConnRegisterTunnelError: case *dupConnRegisterTunnelError:
logger.Info("Already connected to this server, selecting a different one") // don't retry this connection anymore, let supervisor pick new a address
return err, true return err, false
case serverRegisterTunnelError: case *serverRegisterTunnelError:
logger.Errorf("Register tunnel error from server side: %s", castedErr.cause) logger.Errorf("Register tunnel error from server side: %s", err.cause)
// 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 {
logger.Error(activeIncidentsMsg(incidents)) logger.Error(activeIncidentsMsg(incidents))
} }
return castedErr.cause, !castedErr.permanent return err.cause, !err.permanent
case clientRegisterTunnelError: case *clientRegisterTunnelError:
logger.Errorf("Register tunnel error on client side: %s", castedErr.cause) logger.Errorf("Register tunnel error on client side: %s", err.cause)
return err, true return err, true
case muxerShutdownError: case *muxerShutdownError:
logger.Info("Muxer shutdown") logger.Info("Muxer shutdown")
return err, true return err, true
case *ReconnectSignal: case *ReconnectSignal:
logger.Infof("Restarting connection %d due to reconnect signal in %d seconds", connectionIndex, castedErr.Delay) logger.Infof("Restarting connection %d due to reconnect signal in %d seconds", connectionIndex, err.Delay)
castedErr.DelayBeforeReconnect() err.DelayBeforeReconnect()
return err, true return err, true
default: default:
if err == context.Canceled {
logger.Debugf("Serve tunnel error: %s", err)
return err, false
}
logger.Errorf("Serve tunnel error: %s", err) logger.Errorf("Serve tunnel error: %s", err)
return err, true return err, true
} }