mirror of https://github.com/grpc/grpc-go.git
clientconn: stop automatically connecting to idle subchannels returned by picker (#4579)
This commit is contained in:
parent
52546c5d89
commit
dd589923e1
|
@ -1429,26 +1429,14 @@ func (ac *addrConn) resetConnectBackoff() {
|
||||||
ac.mu.Unlock()
|
ac.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// getReadyTransport returns the transport if ac's state is READY.
|
// getReadyTransport returns the transport if ac's state is READY or nil if not.
|
||||||
// Otherwise it returns nil, false.
|
func (ac *addrConn) getReadyTransport() transport.ClientTransport {
|
||||||
// If ac's state is IDLE, it will trigger ac to connect.
|
|
||||||
func (ac *addrConn) getReadyTransport() (transport.ClientTransport, bool) {
|
|
||||||
ac.mu.Lock()
|
ac.mu.Lock()
|
||||||
if ac.state == connectivity.Ready && ac.transport != nil {
|
defer ac.mu.Unlock()
|
||||||
t := ac.transport
|
if ac.state == connectivity.Ready {
|
||||||
ac.mu.Unlock()
|
return ac.transport
|
||||||
return t, true
|
|
||||||
}
|
}
|
||||||
var idle bool
|
return nil
|
||||||
if ac.state == connectivity.Idle {
|
|
||||||
idle = true
|
|
||||||
}
|
|
||||||
ac.mu.Unlock()
|
|
||||||
// Trigger idle ac to connect.
|
|
||||||
if idle {
|
|
||||||
ac.connect()
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tearDown starts to tear down the addrConn.
|
// tearDown starts to tear down the addrConn.
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (pw *pickerWrapper) pick(ctx context.Context, failfast bool, info balancer.
|
||||||
logger.Error("subconn returned from pick is not *acBalancerWrapper")
|
logger.Error("subconn returned from pick is not *acBalancerWrapper")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if t, ok := acw.getAddrConn().getReadyTransport(); ok {
|
if t := acw.getAddrConn().getReadyTransport(); t != nil {
|
||||||
if channelz.IsOn() {
|
if channelz.IsOn() {
|
||||||
return t, doneChannelzWrapper(acw, pickResult.Done), nil
|
return t, doneChannelzWrapper(acw, pickResult.Done), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue