mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 05:09:58 +00:00
TUN-9467: bump coredns to solve CVE
* TUN-9467: bump coredns to solve CVE
This commit is contained in:

committed by
João "Pisco" Fernandes

parent
f8d12c9d39
commit
a408612f26
285
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
285
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -31,14 +32,15 @@ import (
|
||||
|
||||
"google.golang.org/grpc/balancer"
|
||||
"google.golang.org/grpc/balancer/base"
|
||||
"google.golang.org/grpc/balancer/pickfirst"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/internal"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/internal/grpcsync"
|
||||
"google.golang.org/grpc/internal/idle"
|
||||
"google.golang.org/grpc/internal/pretty"
|
||||
iresolver "google.golang.org/grpc/internal/resolver"
|
||||
"google.golang.org/grpc/internal/stats"
|
||||
"google.golang.org/grpc/internal/transport"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"google.golang.org/grpc/resolver"
|
||||
@@ -73,6 +75,8 @@ var (
|
||||
// invalidDefaultServiceConfigErrPrefix is used to prefix the json parsing error for the default
|
||||
// service config.
|
||||
invalidDefaultServiceConfigErrPrefix = "grpc: the provided default service config is invalid"
|
||||
// PickFirstBalancerName is the name of the pick_first balancer.
|
||||
PickFirstBalancerName = pickfirst.Name
|
||||
)
|
||||
|
||||
// The following errors are returned from Dial and DialContext
|
||||
@@ -114,15 +118,30 @@ func (dcs *defaultConfigSelector) SelectConfig(rpcInfo iresolver.RPCInfo) (*ires
|
||||
|
||||
// NewClient creates a new gRPC "channel" for the target URI provided. No I/O
|
||||
// is performed. Use of the ClientConn for RPCs will automatically cause it to
|
||||
// connect. Connect may be used to manually create a connection, but for most
|
||||
// users this is unnecessary.
|
||||
// connect. The Connect method may be called to manually create a connection,
|
||||
// but for most users this should be unnecessary.
|
||||
//
|
||||
// The target name syntax is defined in
|
||||
// https://github.com/grpc/grpc/blob/master/doc/naming.md. e.g. to use dns
|
||||
// resolver, a "dns:///" prefix should be applied to the target.
|
||||
// https://github.com/grpc/grpc/blob/master/doc/naming.md. E.g. to use the dns
|
||||
// name resolver, a "dns:///" prefix may be applied to the target. The default
|
||||
// name resolver will be used if no scheme is detected, or if the parsed scheme
|
||||
// is not a registered name resolver. The default resolver is "dns" but can be
|
||||
// overridden using the resolver package's SetDefaultScheme.
|
||||
//
|
||||
// The DialOptions returned by WithBlock, WithTimeout, and
|
||||
// WithReturnConnectionError are ignored by this function.
|
||||
// Examples:
|
||||
//
|
||||
// - "foo.googleapis.com:8080"
|
||||
// - "dns:///foo.googleapis.com:8080"
|
||||
// - "dns:///foo.googleapis.com"
|
||||
// - "dns:///10.0.0.213:8080"
|
||||
// - "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"
|
||||
// - "dns://8.8.8.8/foo.googleapis.com:8080"
|
||||
// - "dns://8.8.8.8/foo.googleapis.com"
|
||||
// - "zookeeper://zk.example.com:9900/example_service"
|
||||
//
|
||||
// The DialOptions returned by WithBlock, WithTimeout,
|
||||
// WithReturnConnectionError, and FailOnNonTempDialError are ignored by this
|
||||
// function.
|
||||
func NewClient(target string, opts ...DialOption) (conn *ClientConn, err error) {
|
||||
cc := &ClientConn{
|
||||
target: target,
|
||||
@@ -152,6 +171,16 @@ func NewClient(target string, opts ...DialOption) (conn *ClientConn, err error)
|
||||
for _, opt := range opts {
|
||||
opt.apply(&cc.dopts)
|
||||
}
|
||||
|
||||
// Determine the resolver to use.
|
||||
if err := cc.initParsedTargetAndResolverBuilder(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, opt := range globalPerTargetDialOptions {
|
||||
opt.DialOptionForTarget(cc.parsedTarget.URL).apply(&cc.dopts)
|
||||
}
|
||||
|
||||
chainUnaryClientInterceptors(cc)
|
||||
chainStreamClientInterceptors(cc)
|
||||
|
||||
@@ -160,42 +189,38 @@ func NewClient(target string, opts ...DialOption) (conn *ClientConn, err error)
|
||||
}
|
||||
|
||||
if cc.dopts.defaultServiceConfigRawJSON != nil {
|
||||
scpr := parseServiceConfig(*cc.dopts.defaultServiceConfigRawJSON)
|
||||
scpr := parseServiceConfig(*cc.dopts.defaultServiceConfigRawJSON, cc.dopts.maxCallAttempts)
|
||||
if scpr.Err != nil {
|
||||
return nil, fmt.Errorf("%s: %v", invalidDefaultServiceConfigErrPrefix, scpr.Err)
|
||||
}
|
||||
cc.dopts.defaultServiceConfig, _ = scpr.Config.(*ServiceConfig)
|
||||
}
|
||||
cc.mkp = cc.dopts.copts.KeepaliveParams
|
||||
cc.keepaliveParams = cc.dopts.copts.KeepaliveParams
|
||||
|
||||
// Register ClientConn with channelz.
|
||||
if err = cc.initAuthority(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Register ClientConn with channelz. Note that this is only done after
|
||||
// channel creation cannot fail.
|
||||
cc.channelzRegistration(target)
|
||||
|
||||
// TODO: Ideally it should be impossible to error from this function after
|
||||
// channelz registration. This will require removing some channelz logs
|
||||
// from the following functions that can error. Errors can be returned to
|
||||
// the user, and successful logs can be emitted here, after the checks have
|
||||
// passed and channelz is subsequently registered.
|
||||
|
||||
// Determine the resolver to use.
|
||||
if err := cc.parseTargetAndFindResolver(); err != nil {
|
||||
channelz.RemoveEntry(cc.channelz.ID)
|
||||
return nil, err
|
||||
}
|
||||
if err = cc.determineAuthority(); err != nil {
|
||||
channelz.RemoveEntry(cc.channelz.ID)
|
||||
return nil, err
|
||||
}
|
||||
channelz.Infof(logger, cc.channelz, "parsed dial target is: %#v", cc.parsedTarget)
|
||||
channelz.Infof(logger, cc.channelz, "Channel authority set to %q", cc.authority)
|
||||
|
||||
cc.csMgr = newConnectivityStateManager(cc.ctx, cc.channelz)
|
||||
cc.pickerWrapper = newPickerWrapper(cc.dopts.copts.StatsHandlers)
|
||||
|
||||
cc.metricsRecorderList = stats.NewMetricsRecorderList(cc.dopts.copts.StatsHandlers)
|
||||
|
||||
cc.initIdleStateLocked() // Safe to call without the lock, since nothing else has a reference to cc.
|
||||
cc.idlenessMgr = idle.NewManager((*idler)(cc), cc.dopts.idleTimeout)
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
// Dial calls DialContext(context.Background(), target, opts...).
|
||||
//
|
||||
// Deprecated: use NewClient instead. Will be supported throughout 1.x.
|
||||
func Dial(target string, opts ...DialOption) (*ClientConn, error) {
|
||||
return DialContext(context.Background(), target, opts...)
|
||||
}
|
||||
@@ -209,10 +234,17 @@ func Dial(target string, opts ...DialOption) (*ClientConn, error) {
|
||||
// "passthrough" for backward compatibility. This distinction should not matter
|
||||
// to most users, but could matter to legacy users that specify a custom dialer
|
||||
// and expect it to receive the target string directly.
|
||||
//
|
||||
// Deprecated: use NewClient instead. Will be supported throughout 1.x.
|
||||
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) {
|
||||
// At the end of this method, we kick the channel out of idle, rather than
|
||||
// waiting for the first rpc.
|
||||
opts = append([]DialOption{withDefaultScheme("passthrough")}, opts...)
|
||||
//
|
||||
// WithLocalDNSResolution dial option in `grpc.Dial` ensures that it
|
||||
// preserves behavior: when default scheme passthrough is used, skip
|
||||
// hostname resolution, when "dns" is used for resolution, perform
|
||||
// resolution on the client.
|
||||
opts = append([]DialOption{withDefaultScheme("passthrough"), WithLocalDNSResolution()}, opts...)
|
||||
cc, err := NewClient(target, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -582,13 +614,14 @@ type ClientConn struct {
|
||||
cancel context.CancelFunc // Cancelled on close.
|
||||
|
||||
// The following are initialized at dial time, and are read-only after that.
|
||||
target string // User's dial target.
|
||||
parsedTarget resolver.Target // See parseTargetAndFindResolver().
|
||||
authority string // See determineAuthority().
|
||||
dopts dialOptions // Default and user specified dial options.
|
||||
channelz *channelz.Channel // Channelz object.
|
||||
resolverBuilder resolver.Builder // See parseTargetAndFindResolver().
|
||||
idlenessMgr *idle.Manager
|
||||
target string // User's dial target.
|
||||
parsedTarget resolver.Target // See initParsedTargetAndResolverBuilder().
|
||||
authority string // See initAuthority().
|
||||
dopts dialOptions // Default and user specified dial options.
|
||||
channelz *channelz.Channel // Channelz object.
|
||||
resolverBuilder resolver.Builder // See initParsedTargetAndResolverBuilder().
|
||||
idlenessMgr *idle.Manager
|
||||
metricsRecorderList *stats.MetricsRecorderList
|
||||
|
||||
// The following provide their own synchronization, and therefore don't
|
||||
// require cc.mu to be held to access them.
|
||||
@@ -604,7 +637,7 @@ type ClientConn struct {
|
||||
balancerWrapper *ccBalancerWrapper // Always recreated whenever entering idle to simplify Close.
|
||||
sc *ServiceConfig // Latest service config received from the resolver.
|
||||
conns map[*addrConn]struct{} // Set to nil on close.
|
||||
mkp keepalive.ClientParameters // May be updated upon receipt of a GoAway.
|
||||
keepaliveParams keepalive.ClientParameters // May be updated upon receipt of a GoAway.
|
||||
// firstResolveEvent is used to track whether the name resolver sent us at
|
||||
// least one update. RPCs block on this event. May be accessed without mu
|
||||
// if we know we cannot be asked to enter idle mode while accessing it (e.g.
|
||||
@@ -618,11 +651,6 @@ type ClientConn struct {
|
||||
|
||||
// WaitForStateChange waits until the connectivity.State of ClientConn changes from sourceState or
|
||||
// ctx expires. A true value is returned in former case and false in latter.
|
||||
//
|
||||
// # Experimental
|
||||
//
|
||||
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
|
||||
// later release.
|
||||
func (cc *ClientConn) WaitForStateChange(ctx context.Context, sourceState connectivity.State) bool {
|
||||
ch := cc.csMgr.getNotifyChan()
|
||||
if cc.csMgr.getState() != sourceState {
|
||||
@@ -637,11 +665,6 @@ func (cc *ClientConn) WaitForStateChange(ctx context.Context, sourceState connec
|
||||
}
|
||||
|
||||
// GetState returns the connectivity.State of ClientConn.
|
||||
//
|
||||
// # Experimental
|
||||
//
|
||||
// Notice: This API is EXPERIMENTAL and may be changed or removed in a later
|
||||
// release.
|
||||
func (cc *ClientConn) GetState() connectivity.State {
|
||||
return cc.csMgr.getState()
|
||||
}
|
||||
@@ -688,8 +711,7 @@ func (cc *ClientConn) waitForResolvedAddrs(ctx context.Context) error {
|
||||
var emptyServiceConfig *ServiceConfig
|
||||
|
||||
func init() {
|
||||
balancer.Register(pickfirstBuilder{})
|
||||
cfg := parseServiceConfig("{}")
|
||||
cfg := parseServiceConfig("{}", defaultMaxCallAttempts)
|
||||
if cfg.Err != nil {
|
||||
panic(fmt.Sprintf("impossible error parsing empty service config: %v", cfg.Err))
|
||||
}
|
||||
@@ -772,10 +794,7 @@ func (cc *ClientConn) updateResolverStateAndUnlock(s resolver.State, err error)
|
||||
}
|
||||
}
|
||||
|
||||
var balCfg serviceconfig.LoadBalancingConfig
|
||||
if cc.sc != nil && cc.sc.lbConfig != nil {
|
||||
balCfg = cc.sc.lbConfig
|
||||
}
|
||||
balCfg := cc.sc.lbConfig
|
||||
bw := cc.balancerWrapper
|
||||
cc.mu.Unlock()
|
||||
|
||||
@@ -805,17 +824,11 @@ func (cc *ClientConn) applyFailingLBLocked(sc *serviceconfig.ParseResult) {
|
||||
cc.csMgr.updateState(connectivity.TransientFailure)
|
||||
}
|
||||
|
||||
// Makes a copy of the input addresses slice and clears out the balancer
|
||||
// attributes field. Addresses are passed during subconn creation and address
|
||||
// update operations. In both cases, we will clear the balancer attributes by
|
||||
// calling this function, and therefore we will be able to use the Equal method
|
||||
// provided by the resolver.Address type for comparison.
|
||||
func copyAddressesWithoutBalancerAttributes(in []resolver.Address) []resolver.Address {
|
||||
// Makes a copy of the input addresses slice. Addresses are passed during
|
||||
// subconn creation and address update operations.
|
||||
func copyAddresses(in []resolver.Address) []resolver.Address {
|
||||
out := make([]resolver.Address, len(in))
|
||||
for i := range in {
|
||||
out[i] = in[i]
|
||||
out[i].BalancerAttributes = nil
|
||||
}
|
||||
copy(out, in)
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -830,14 +843,16 @@ func (cc *ClientConn) newAddrConnLocked(addrs []resolver.Address, opts balancer.
|
||||
ac := &addrConn{
|
||||
state: connectivity.Idle,
|
||||
cc: cc,
|
||||
addrs: copyAddressesWithoutBalancerAttributes(addrs),
|
||||
addrs: copyAddresses(addrs),
|
||||
scopts: opts,
|
||||
dopts: cc.dopts,
|
||||
channelz: channelz.RegisterSubChannel(cc.channelz, ""),
|
||||
resetBackoff: make(chan struct{}),
|
||||
stateChan: make(chan struct{}),
|
||||
}
|
||||
ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
|
||||
// Start with our address set to the first address; this may be updated if
|
||||
// we connect to different addresses.
|
||||
ac.channelz.ChannelMetrics.Target.Store(&addrs[0].Addr)
|
||||
|
||||
channelz.AddTraceEvent(logger, ac.channelz, 0, &channelz.TraceEvent{
|
||||
Desc: "Subchannel created",
|
||||
@@ -871,7 +886,13 @@ func (cc *ClientConn) Target() string {
|
||||
return cc.target
|
||||
}
|
||||
|
||||
// CanonicalTarget returns the canonical target string of the ClientConn.
|
||||
// CanonicalTarget returns the canonical target string used when creating cc.
|
||||
//
|
||||
// This always has the form "<scheme>://[authority]/<endpoint>". For example:
|
||||
//
|
||||
// - "dns:///example.com:42"
|
||||
// - "dns://8.8.8.8/example.com:42"
|
||||
// - "unix:///path/to/socket"
|
||||
func (cc *ClientConn) CanonicalTarget() string {
|
||||
return cc.parsedTarget.String()
|
||||
}
|
||||
@@ -908,32 +929,37 @@ func (ac *addrConn) connect() error {
|
||||
ac.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
ac.mu.Unlock()
|
||||
|
||||
ac.resetTransport()
|
||||
ac.resetTransportAndUnlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func equalAddresses(a, b []resolver.Address) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, v := range a {
|
||||
if !v.Equal(b[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
// equalAddressIgnoringBalAttributes returns true is a and b are considered equal.
|
||||
// This is different from the Equal method on the resolver.Address type which
|
||||
// considers all fields to determine equality. Here, we only consider fields
|
||||
// that are meaningful to the subConn.
|
||||
func equalAddressIgnoringBalAttributes(a, b *resolver.Address) bool {
|
||||
return a.Addr == b.Addr && a.ServerName == b.ServerName &&
|
||||
a.Attributes.Equal(b.Attributes) &&
|
||||
a.Metadata == b.Metadata
|
||||
}
|
||||
|
||||
func equalAddressesIgnoringBalAttributes(a, b []resolver.Address) bool {
|
||||
return slices.EqualFunc(a, b, func(a, b resolver.Address) bool { return equalAddressIgnoringBalAttributes(&a, &b) })
|
||||
}
|
||||
|
||||
// updateAddrs updates ac.addrs with the new addresses list and handles active
|
||||
// connections or connection attempts.
|
||||
func (ac *addrConn) updateAddrs(addrs []resolver.Address) {
|
||||
ac.mu.Lock()
|
||||
channelz.Infof(logger, ac.channelz, "addrConn: updateAddrs curAddr: %v, addrs: %v", pretty.ToJSON(ac.curAddr), pretty.ToJSON(addrs))
|
||||
addrs = copyAddresses(addrs)
|
||||
limit := len(addrs)
|
||||
if limit > 5 {
|
||||
limit = 5
|
||||
}
|
||||
channelz.Infof(logger, ac.channelz, "addrConn: updateAddrs addrs (%d of %d): %v", limit, len(addrs), addrs[:limit])
|
||||
|
||||
addrs = copyAddressesWithoutBalancerAttributes(addrs)
|
||||
if equalAddresses(ac.addrs, addrs) {
|
||||
ac.mu.Lock()
|
||||
if equalAddressesIgnoringBalAttributes(ac.addrs, addrs) {
|
||||
ac.mu.Unlock()
|
||||
return
|
||||
}
|
||||
@@ -952,7 +978,7 @@ func (ac *addrConn) updateAddrs(addrs []resolver.Address) {
|
||||
// Try to find the connected address.
|
||||
for _, a := range addrs {
|
||||
a.ServerName = ac.cc.getServerName(a)
|
||||
if a.Equal(ac.curAddr) {
|
||||
if equalAddressIgnoringBalAttributes(&a, &ac.curAddr) {
|
||||
// We are connected to a valid address, so do nothing but
|
||||
// update the addresses.
|
||||
ac.mu.Unlock()
|
||||
@@ -978,11 +1004,9 @@ func (ac *addrConn) updateAddrs(addrs []resolver.Address) {
|
||||
ac.updateConnectivityState(connectivity.Idle, nil)
|
||||
}
|
||||
|
||||
ac.mu.Unlock()
|
||||
|
||||
// Since we were connecting/connected, we should start a new connection
|
||||
// attempt.
|
||||
go ac.resetTransport()
|
||||
go ac.resetTransportAndUnlock()
|
||||
}
|
||||
|
||||
// getServerName determines the serverName to be used in the connection
|
||||
@@ -1138,10 +1162,15 @@ func (cc *ClientConn) Close() error {
|
||||
|
||||
<-cc.resolverWrapper.serializer.Done()
|
||||
<-cc.balancerWrapper.serializer.Done()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for ac := range conns {
|
||||
ac.tearDown(ErrClientConnClosing)
|
||||
wg.Add(1)
|
||||
go func(ac *addrConn) {
|
||||
defer wg.Done()
|
||||
ac.tearDown(ErrClientConnClosing)
|
||||
}(ac)
|
||||
}
|
||||
wg.Wait()
|
||||
cc.addTraceEvent("deleted")
|
||||
// TraceEvent needs to be called before RemoveEntry, as TraceEvent may add
|
||||
// trace reference to the entity being deleted, and thus prevent it from being
|
||||
@@ -1167,13 +1196,16 @@ type addrConn struct {
|
||||
// is received, transport is closed, ac has been torn down).
|
||||
transport transport.ClientTransport // The current transport.
|
||||
|
||||
// This mutex is used on the RPC path, so its usage should be minimized as
|
||||
// much as possible.
|
||||
// TODO: Find a lock-free way to retrieve the transport and state from the
|
||||
// addrConn.
|
||||
mu sync.Mutex
|
||||
curAddr resolver.Address // The current address.
|
||||
addrs []resolver.Address // All addresses that the resolver resolved to.
|
||||
|
||||
// Use updateConnectivityState for updating addrConn's connectivity state.
|
||||
state connectivity.State
|
||||
stateChan chan struct{} // closed and recreated on every state change.
|
||||
state connectivity.State
|
||||
|
||||
backoffIdx int // Needs to be stateful for resetConnectBackoff.
|
||||
resetBackoff chan struct{}
|
||||
@@ -1186,9 +1218,6 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error)
|
||||
if ac.state == s {
|
||||
return
|
||||
}
|
||||
// When changing states, reset the state change channel.
|
||||
close(ac.stateChan)
|
||||
ac.stateChan = make(chan struct{})
|
||||
ac.state = s
|
||||
ac.channelz.ChannelMetrics.State.Store(&s)
|
||||
if lastErr == nil {
|
||||
@@ -1196,25 +1225,26 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error)
|
||||
} else {
|
||||
channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v, last error: %s", s, lastErr)
|
||||
}
|
||||
ac.acbw.updateState(s, lastErr)
|
||||
ac.acbw.updateState(s, ac.curAddr, lastErr)
|
||||
}
|
||||
|
||||
// adjustParams updates parameters used to create transports upon
|
||||
// receiving a GoAway.
|
||||
func (ac *addrConn) adjustParams(r transport.GoAwayReason) {
|
||||
switch r {
|
||||
case transport.GoAwayTooManyPings:
|
||||
if r == transport.GoAwayTooManyPings {
|
||||
v := 2 * ac.dopts.copts.KeepaliveParams.Time
|
||||
ac.cc.mu.Lock()
|
||||
if v > ac.cc.mkp.Time {
|
||||
ac.cc.mkp.Time = v
|
||||
if v > ac.cc.keepaliveParams.Time {
|
||||
ac.cc.keepaliveParams.Time = v
|
||||
}
|
||||
ac.cc.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (ac *addrConn) resetTransport() {
|
||||
ac.mu.Lock()
|
||||
// resetTransportAndUnlock unconditionally connects the addrConn.
|
||||
//
|
||||
// ac.mu must be held by the caller, and this function will guarantee it is released.
|
||||
func (ac *addrConn) resetTransportAndUnlock() {
|
||||
acCtx := ac.ctx
|
||||
if acCtx.Err() != nil {
|
||||
ac.mu.Unlock()
|
||||
@@ -1245,6 +1275,8 @@ func (ac *addrConn) resetTransport() {
|
||||
ac.mu.Unlock()
|
||||
|
||||
if err := ac.tryAllAddrs(acCtx, addrs, connectDeadline); err != nil {
|
||||
// TODO: #7534 - Move re-resolution requests into the pick_first LB policy
|
||||
// to ensure one resolution request per pass instead of per subconn failure.
|
||||
ac.cc.resolveNow(resolver.ResolveNowOptions{})
|
||||
ac.mu.Lock()
|
||||
if acCtx.Err() != nil {
|
||||
@@ -1286,19 +1318,20 @@ func (ac *addrConn) resetTransport() {
|
||||
ac.mu.Unlock()
|
||||
}
|
||||
|
||||
// tryAllAddrs tries to creates a connection to the addresses, and stop when at
|
||||
// tryAllAddrs tries to create a connection to the addresses, and stop when at
|
||||
// the first successful one. It returns an error if no address was successfully
|
||||
// connected, or updates ac appropriately with the new transport.
|
||||
func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time) error {
|
||||
var firstConnErr error
|
||||
for _, addr := range addrs {
|
||||
ac.channelz.ChannelMetrics.Target.Store(&addr.Addr)
|
||||
if ctx.Err() != nil {
|
||||
return errConnClosing
|
||||
}
|
||||
ac.mu.Lock()
|
||||
|
||||
ac.cc.mu.RLock()
|
||||
ac.dopts.copts.KeepaliveParams = ac.cc.mkp
|
||||
ac.dopts.copts.KeepaliveParams = ac.cc.keepaliveParams
|
||||
ac.cc.mu.RUnlock()
|
||||
|
||||
copts := ac.dopts.copts
|
||||
@@ -1362,7 +1395,7 @@ func (ac *addrConn) createTransport(ctx context.Context, addr resolver.Address,
|
||||
defer cancel()
|
||||
copts.ChannelzParent = ac.channelz
|
||||
|
||||
newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, addr, copts, onClose)
|
||||
newTr, err := transport.NewHTTP2Client(connectCtx, ac.cc.ctx, addr, copts, onClose)
|
||||
if err != nil {
|
||||
if logger.V(2) {
|
||||
logger.Infof("Creating new client transport to %q: %v", addr, err)
|
||||
@@ -1436,7 +1469,7 @@ func (ac *addrConn) startHealthCheck(ctx context.Context) {
|
||||
if !ac.scopts.HealthCheckEnabled {
|
||||
return
|
||||
}
|
||||
healthCheckFunc := ac.cc.dopts.healthCheckFunc
|
||||
healthCheckFunc := internal.HealthCheckFunc
|
||||
if healthCheckFunc == nil {
|
||||
// The health package is not imported to set health check function.
|
||||
//
|
||||
@@ -1468,7 +1501,7 @@ func (ac *addrConn) startHealthCheck(ctx context.Context) {
|
||||
}
|
||||
// Start the health checking stream.
|
||||
go func() {
|
||||
err := ac.cc.dopts.healthCheckFunc(ctx, newStream, setConnectivityState, healthCheckConfig.ServiceName)
|
||||
err := healthCheckFunc(ctx, newStream, setConnectivityState, healthCheckConfig.ServiceName)
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.Unimplemented {
|
||||
channelz.Error(logger, ac.channelz, "Subchannel health check is unimplemented at server side, thus health check is disabled")
|
||||
@@ -1497,29 +1530,6 @@ func (ac *addrConn) getReadyTransport() transport.ClientTransport {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getTransport waits until the addrconn is ready and returns the transport.
|
||||
// If the context expires first, returns an appropriate status. If the
|
||||
// addrConn is stopped first, returns an Unavailable status error.
|
||||
func (ac *addrConn) getTransport(ctx context.Context) (transport.ClientTransport, error) {
|
||||
for ctx.Err() == nil {
|
||||
ac.mu.Lock()
|
||||
t, state, sc := ac.transport, ac.state, ac.stateChan
|
||||
ac.mu.Unlock()
|
||||
if state == connectivity.Ready {
|
||||
return t, nil
|
||||
}
|
||||
if state == connectivity.Shutdown {
|
||||
return nil, status.Errorf(codes.Unavailable, "SubConn shutting down")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-sc:
|
||||
}
|
||||
}
|
||||
return nil, status.FromContextError(ctx.Err()).Err()
|
||||
}
|
||||
|
||||
// tearDown starts to tear down the addrConn.
|
||||
//
|
||||
// Note that tearDown doesn't remove ac from ac.cc.conns, so the addrConn struct
|
||||
@@ -1566,7 +1576,7 @@ func (ac *addrConn) tearDown(err error) {
|
||||
} else {
|
||||
// Hard close the transport when the channel is entering idle or is
|
||||
// being shutdown. In the case where the channel is being shutdown,
|
||||
// closing of transports is also taken care of by cancelation of cc.ctx.
|
||||
// closing of transports is also taken care of by cancellation of cc.ctx.
|
||||
// But in the case where the channel is entering idle, we need to
|
||||
// explicitly close the transports here. Instead of distinguishing
|
||||
// between these two cases, it is simpler to close the transport
|
||||
@@ -1657,22 +1667,19 @@ func (cc *ClientConn) connectionError() error {
|
||||
return cc.lastConnectionError
|
||||
}
|
||||
|
||||
// parseTargetAndFindResolver parses the user's dial target and stores the
|
||||
// parsed target in `cc.parsedTarget`.
|
||||
// initParsedTargetAndResolverBuilder parses the user's dial target and stores
|
||||
// the parsed target in `cc.parsedTarget`.
|
||||
//
|
||||
// The resolver to use is determined based on the scheme in the parsed target
|
||||
// and the same is stored in `cc.resolverBuilder`.
|
||||
//
|
||||
// Doesn't grab cc.mu as this method is expected to be called only at Dial time.
|
||||
func (cc *ClientConn) parseTargetAndFindResolver() error {
|
||||
channelz.Infof(logger, cc.channelz, "original dial target is: %q", cc.target)
|
||||
func (cc *ClientConn) initParsedTargetAndResolverBuilder() error {
|
||||
logger.Infof("original dial target is: %q", cc.target)
|
||||
|
||||
var rb resolver.Builder
|
||||
parsedTarget, err := parseTarget(cc.target)
|
||||
if err != nil {
|
||||
channelz.Infof(logger, cc.channelz, "dial target %q parse failed: %v", cc.target, err)
|
||||
} else {
|
||||
channelz.Infof(logger, cc.channelz, "parsed dial target is: %#v", parsedTarget)
|
||||
if err == nil {
|
||||
rb = cc.getResolver(parsedTarget.URL.Scheme)
|
||||
if rb != nil {
|
||||
cc.parsedTarget = parsedTarget
|
||||
@@ -1691,15 +1698,12 @@ func (cc *ClientConn) parseTargetAndFindResolver() error {
|
||||
defScheme = resolver.GetDefaultScheme()
|
||||
}
|
||||
|
||||
channelz.Infof(logger, cc.channelz, "fallback to scheme %q", defScheme)
|
||||
canonicalTarget := defScheme + ":///" + cc.target
|
||||
|
||||
parsedTarget, err = parseTarget(canonicalTarget)
|
||||
if err != nil {
|
||||
channelz.Infof(logger, cc.channelz, "dial target %q parse failed: %v", canonicalTarget, err)
|
||||
return err
|
||||
}
|
||||
channelz.Infof(logger, cc.channelz, "parsed dial target is: %+v", parsedTarget)
|
||||
rb = cc.getResolver(parsedTarget.URL.Scheme)
|
||||
if rb == nil {
|
||||
return fmt.Errorf("could not get resolver for default scheme: %q", parsedTarget.URL.Scheme)
|
||||
@@ -1739,7 +1743,7 @@ func encodeAuthority(authority string) string {
|
||||
return false
|
||||
case '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=': // Subdelim characters
|
||||
return false
|
||||
case ':', '[', ']', '@': // Authority related delimeters
|
||||
case ':', '[', ']', '@': // Authority related delimiters
|
||||
return false
|
||||
}
|
||||
// Everything else must be escaped.
|
||||
@@ -1789,7 +1793,7 @@ func encodeAuthority(authority string) string {
|
||||
// credentials do not match the authority configured through the dial option.
|
||||
//
|
||||
// Doesn't grab cc.mu as this method is expected to be called only at Dial time.
|
||||
func (cc *ClientConn) determineAuthority() error {
|
||||
func (cc *ClientConn) initAuthority() error {
|
||||
dopts := cc.dopts
|
||||
// Historically, we had two options for users to specify the serverName or
|
||||
// authority for a channel. One was through the transport credentials
|
||||
@@ -1822,6 +1826,5 @@ func (cc *ClientConn) determineAuthority() error {
|
||||
} else {
|
||||
cc.authority = encodeAuthority(endpoint)
|
||||
}
|
||||
channelz.Infof(logger, cc.channelz, "Channel authority set to %q", cc.authority)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user