Skip to content

Commit

Permalink
clientconn: stop automatically connecting to idle subchannels returne…
Browse files Browse the repository at this point in the history
…d by picker (#4579)
  • Loading branch information
dfawley committed Jul 2, 2021
1 parent 52546c5 commit dd58992
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions clientconn.go
Expand Up @@ -1429,26 +1429,14 @@ func (ac *addrConn) resetConnectBackoff() {
ac.mu.Unlock()
}

// getReadyTransport returns the transport if ac's state is READY.
// Otherwise it returns nil, false.
// If ac's state is IDLE, it will trigger ac to connect.
func (ac *addrConn) getReadyTransport() (transport.ClientTransport, bool) {
// getReadyTransport returns the transport if ac's state is READY or nil if not.
func (ac *addrConn) getReadyTransport() transport.ClientTransport {
ac.mu.Lock()
if ac.state == connectivity.Ready && ac.transport != nil {
t := ac.transport
ac.mu.Unlock()
return t, true
}
var idle bool
if ac.state == connectivity.Idle {
idle = true
}
ac.mu.Unlock()
// Trigger idle ac to connect.
if idle {
ac.connect()
defer ac.mu.Unlock()
if ac.state == connectivity.Ready {
return ac.transport
}
return nil, false
return nil
}

// tearDown starts to tear down the addrConn.
Expand Down
2 changes: 1 addition & 1 deletion picker_wrapper.go
Expand Up @@ -147,7 +147,7 @@ func (pw *pickerWrapper) pick(ctx context.Context, failfast bool, info balancer.
logger.Error("subconn returned from pick is not *acBalancerWrapper")
continue
}
if t, ok := acw.getAddrConn().getReadyTransport(); ok {
if t := acw.getAddrConn().getReadyTransport(); t != nil {
if channelz.IsOn() {
return t, doneChannelzWrapper(acw, pickResult.Done), nil
}
Expand Down

0 comments on commit dd58992

Please sign in to comment.