From dd589923e1a17f5cc7c667359ae12d56bc1d3113 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Fri, 2 Jul 2021 16:21:46 -0700 Subject: [PATCH] clientconn: stop automatically connecting to idle subchannels returned by picker (#4579) --- clientconn.go | 24 ++++++------------------ picker_wrapper.go | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/clientconn.go b/clientconn.go index 5cef39295..b2bccfed1 100644 --- a/clientconn.go +++ b/clientconn.go @@ -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 + defer ac.mu.Unlock() + if ac.state == connectivity.Ready { + return ac.transport } - var idle bool - if ac.state == connectivity.Idle { - idle = true - } - ac.mu.Unlock() - // Trigger idle ac to connect. - if idle { - ac.connect() - } - return nil, false + return nil } // tearDown starts to tear down the addrConn. diff --git a/picker_wrapper.go b/picker_wrapper.go index a58174b6f..0878ada9d 100644 --- a/picker_wrapper.go +++ b/picker_wrapper.go @@ -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 }