mirror of
https://github.com/fumiama/terasu-cloudflared.git
synced 2026-06-05 00:50:24 +08:00
Corrects the pattern of using errgroup's and context cancellation to simplify the logic for canceling extra routines for the QUIC connection. This is because the extra context cancellation is redundant with the fact that the errgroup also cancels it's own provided context when a routine returns (error or not). For the datagram handler specifically, since it can respond faster to a context cancellation from the QUIC connection, we wrap the error before surfacing it outside of the QUIC connection scope to the supervisor. Additionally, the supervisor will look for this error type to check if it should retry the QUIC connection. These two operations are required because the supervisor does not look for a context canceled error when deciding to retry a connection. If a context canceled from the datagram handler were to be returned up to the supervisor on the initial connection, the cloudflared application would exit. We want to ensure that cloudflared maintains connection attempts even if any of the services on-top of a QUIC connection fail (datagram handler in this case). Additional logging is also introduced along these paths to help with understanding the error conditions from the specific handlers on-top of a QUIC connection. Related CUSTESC-53681 Closes TUN-9610
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package connection
|
|
|
|
import (
|
|
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
|
|
)
|
|
|
|
const (
|
|
DuplicateConnectionError = "EDUPCONN"
|
|
)
|
|
|
|
type DupConnRegisterTunnelError struct{}
|
|
|
|
var errDuplicationConnection = DupConnRegisterTunnelError{}
|
|
|
|
func (e DupConnRegisterTunnelError) Error() string {
|
|
return "already connected to this server, trying another address"
|
|
}
|
|
|
|
// Dial to edge server with quic failed
|
|
type EdgeQuicDialError struct {
|
|
Cause error
|
|
}
|
|
|
|
func (e *EdgeQuicDialError) Error() string {
|
|
return "failed to dial to edge with quic: " + e.Cause.Error()
|
|
}
|
|
|
|
func (e *EdgeQuicDialError) Unwrap() error {
|
|
return e.Cause
|
|
}
|
|
|
|
// RegisterTunnel error from server
|
|
type ServerRegisterTunnelError struct {
|
|
Cause error
|
|
Permanent bool
|
|
}
|
|
|
|
func (e ServerRegisterTunnelError) Error() string {
|
|
return e.Cause.Error()
|
|
}
|
|
|
|
func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
|
|
if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
|
|
return ServerRegisterTunnelError{
|
|
Cause: retryable.Unwrap(),
|
|
Permanent: false,
|
|
}
|
|
}
|
|
return ServerRegisterTunnelError{
|
|
Cause: err,
|
|
Permanent: true,
|
|
}
|
|
}
|
|
|
|
type ControlStreamError struct{}
|
|
|
|
var _ error = &ControlStreamError{}
|
|
|
|
func (e *ControlStreamError) Error() string {
|
|
return "control stream encountered a failure while serving"
|
|
}
|
|
|
|
type StreamListenerError struct{}
|
|
|
|
var _ error = &StreamListenerError{}
|
|
|
|
func (e *StreamListenerError) Error() string {
|
|
return "accept stream listener encountered a failure while serving"
|
|
}
|
|
|
|
type DatagramManagerError struct{}
|
|
|
|
var _ error = &DatagramManagerError{}
|
|
|
|
func (e *DatagramManagerError) Error() string {
|
|
return "datagram manager encountered a failure while serving"
|
|
}
|