Skip to content

Commit a87e923

Browse files
authored
channelz: fix missing Target on SubChannel type (#7189)
1 parent 273fe14 commit a87e923

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clientconn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,9 @@ func (cc *ClientConn) newAddrConnLocked(addrs []resolver.Address, opts balancer.
842842
stateChan: make(chan struct{}),
843843
}
844844
ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
845+
// Start with our address set to the first address; this may be updated if
846+
// we connect to different addresses.
847+
ac.channelz.ChannelMetrics.Target.Store(&addrs[0].Addr)
845848

846849
channelz.AddTraceEvent(logger, ac.channelz, 0, &channelz.TraceEvent{
847850
Desc: "Subchannel created",
@@ -1304,6 +1307,7 @@ func (ac *addrConn) resetTransport() {
13041307
func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time) error {
13051308
var firstConnErr error
13061309
for _, addr := range addrs {
1310+
ac.channelz.ChannelMetrics.Target.Store(&addr.Addr)
13071311
if ctx.Err() != nil {
13081312
return errConnClosing
13091313
}

test/channelz_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ func (s) TestCZGetSubChannel(t *testing.T) {
158158
if sc == nil {
159159
return false, fmt.Errorf("subchannel with id %v is nil", scid)
160160
}
161+
target := sc.ChannelMetrics.Target.Load()
162+
if target == nil || !strings.HasPrefix(*target, "localhost") {
163+
t.Fatalf("subchannel target must never be set incorrectly; got: %v, want <HasPrefix('localhost')>", target)
164+
}
161165
state := sc.ChannelMetrics.State.Load()
162166
if state == nil || *state != connectivity.Ready {
163167
return false, fmt.Errorf("Got subchannel state=%v; want %q", state, connectivity.Ready)

0 commit comments

Comments
 (0)