Skip to content

Commit 32a58f6

Browse files
committed
client: Drop two calls to pretty.ToJSON and move code outside of lock
1 parent b37cd81 commit 32a58f6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

clientconn.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"google.golang.org/grpc/internal/channelz"
3838
"google.golang.org/grpc/internal/grpcsync"
3939
"google.golang.org/grpc/internal/idle"
40-
"google.golang.org/grpc/internal/pretty"
4140
iresolver "google.golang.org/grpc/internal/resolver"
4241
"google.golang.org/grpc/internal/transport"
4342
"google.golang.org/grpc/keepalive"
@@ -934,10 +933,14 @@ func equalAddresses(a, b []resolver.Address) bool {
934933
// updateAddrs updates ac.addrs with the new addresses list and handles active
935934
// connections or connection attempts.
936935
func (ac *addrConn) updateAddrs(addrs []resolver.Address) {
937-
ac.mu.Lock()
938-
channelz.Infof(logger, ac.channelz, "addrConn: updateAddrs curAddr: %v, addrs: %v", pretty.ToJSON(ac.curAddr), pretty.ToJSON(addrs))
939-
940936
addrs = copyAddressesWithoutBalancerAttributes(addrs)
937+
limit := len(addrs)
938+
if limit > 5 {
939+
limit = 5
940+
}
941+
channelz.Infof(logger, ac.channelz, "addrConn: updateAddrs addrs (%d of %d): %v", limit, len(addrs), addrs[:limit])
942+
943+
ac.mu.Lock()
941944
if equalAddresses(ac.addrs, addrs) {
942945
ac.mu.Unlock()
943946
return
@@ -1172,6 +1175,10 @@ type addrConn struct {
11721175
// is received, transport is closed, ac has been torn down).
11731176
transport transport.ClientTransport // The current transport.
11741177

1178+
// This mutex is used on the RPC path, so its usage should be minimized as
1179+
// much as possible.
1180+
// TODO: Find a lock-free way to retrieve the transport and state from the
1181+
// addrConn without a lock.
11751182
mu sync.Mutex
11761183
curAddr resolver.Address // The current address.
11771184
addrs []resolver.Address // All addresses that the resolver resolved to.

0 commit comments

Comments
 (0)