cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
connection/errors.go
68lines · modecode
TUN-3811: Better error reporting on http2 connection termination. Registration errors from control loop are now propagated out of the connection server code. Unified error handling between h2mux and http2 connections so we log and retry errors the same way, regardless of underlying transport.a945518
| 1 | package connection |
| 2 | |
| 3 | import ( |
| 4 | "github.com/cloudflare/cloudflared/edgediscovery" |
| 5 | "github.com/cloudflare/cloudflared/h2mux" |
| 6 | tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs" |
| 7 | ) |
| 8 | |
| 9 | const ( |
| 10 | DuplicateConnectionError = "EDUPCONN" |
| 11 | ) |
| 12 | |
| 13 | type DupConnRegisterTunnelError struct{} |
| 14 | |
| 15 | var errDuplicationConnection = DupConnRegisterTunnelError{} |
| 16 | |
| 17 | func (e DupConnRegisterTunnelError) Error() string { |
| 18 | return "already connected to this server, trying another address" |
| 19 | } |
| 20 | |
| 21 | // RegisterTunnel error from server |
| 22 | type ServerRegisterTunnelError struct { |
| 23 | Cause error |
| 24 | Permanent bool |
| 25 | } |
| 26 | |
| 27 | func (e ServerRegisterTunnelError) Error() string { |
| 28 | return e.Cause.Error() |
| 29 | } |
| 30 | |
| 31 | func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError { |
| 32 | if retryable, ok := err.(*tunnelpogs.RetryableError); ok { |
| 33 | return ServerRegisterTunnelError{ |
| 34 | Cause: retryable.Unwrap(), |
| 35 | Permanent: false, |
| 36 | } |
| 37 | } |
| 38 | return ServerRegisterTunnelError{ |
| 39 | Cause: err, |
| 40 | Permanent: true, |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | type muxerShutdownError struct{} |
| 45 | |
| 46 | func (e muxerShutdownError) Error() string { |
| 47 | return "muxer shutdown" |
| 48 | } |
| 49 | |
| 50 | var errMuxerStopped = muxerShutdownError{} |
| 51 | |
| 52 | func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool { |
| 53 | log := observer.log.With(). |
| 54 | Uint8(LogFieldConnIndex, connIndex). |
| 55 | Err(err). |
| 56 | Logger() |
| 57 | |
| 58 | switch err.(type) { |
| 59 | case edgediscovery.DialError: |
| 60 | log.Error().Msg("Connection unable to dial edge") |
| 61 | case h2mux.MuxerHandshakeError: |
| 62 | log.Error().Msg("Connection handshake with edge server failed") |
| 63 | default: |
| 64 | log.Error().Msg("Connection failed") |
| 65 | return false |
| 66 | } |
| 67 | return true |
| 68 | } |