Skip to content

Commit 0f3086d

Browse files
authored
Fix minor issues not covered by PR #9137 (#9147)
This PR is a follow up of already merged PR #9137 Delivers minor fixes for nit comments unaddressed in the previous PR RELEASE NOTES: N/A
1 parent fef07fb commit 0f3086d

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

balancer/rls/balancer_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ func waitForConnectivityState(ctx context.Context, t *testing.T, ch *buffer.Unbo
999999
select {
10001000
case gotState := <-ch.Get():
10011001
ch.Load()
1002+
if gotState == nil {
1003+
t.Fatalf("Channel closed while waiting for RLS control channel to become one of %v", wants)
1004+
}
10021005
got := gotState.(connectivity.State)
10031006
for _, want := range wants {
10041007
if got == want {
@@ -1048,8 +1051,10 @@ func (s) TestControlChannelConnectivityStateMonitoring(t *testing.T) {
10481051
wrappedSubscriber := &wrappingConnectivityStateSubscriber{connStateCh: buffer.NewUnbounded()}
10491052
origConnectivityStateSubscriber := newConnectivityStateSubscriber
10501053
newConnectivityStateSubscriber = func(delegate grpcsync.Subscriber) grpcsync.Subscriber {
1051-
wrappedSubscriber.delegate = delegate
1052-
return wrappedSubscriber
1054+
return &wrappingConnectivityStateSubscriber{
1055+
delegate: delegate,
1056+
connStateCh: wrappedSubscriber.connStateCh,
1057+
}
10531058
}
10541059
defer func() { newConnectivityStateSubscriber = origConnectivityStateSubscriber }()
10551060

@@ -1116,10 +1121,10 @@ func (s) TestControlChannelConnectivityStateMonitoring(t *testing.T) {
11161121
// and move it to TRANSIENT_FAILURE.
11171122
ctxFailed := metadata.AppendToOutgoingContext(ctx, "n1", "v1")
11181123
makeTestRPCAndVerifyError(ctxFailed, t, cc, codes.Unavailable, nil)
1119-
}
11201124

1121-
// Wait for the control channel to move to TRANSIENT_FAILURE.
1122-
waitForConnectivityState(ctx, t, wrappedSubscriber.connStateCh, connectivity.TransientFailure)
1125+
// Wait for the control channel to move to TRANSIENT_FAILURE.
1126+
waitForConnectivityState(ctx, t, wrappedSubscriber.connStateCh, connectivity.TransientFailure)
1127+
}
11231128

11241129
// Restart the RLS server.
11251130
lis.Restart()
@@ -1191,8 +1196,10 @@ func (s) TestControlChannelIdleTransitionNoBackoffReset(t *testing.T) {
11911196
wrappedSubscriber := &wrappingConnectivityStateSubscriber{connStateCh: buffer.NewUnbounded()}
11921197
origConnectivityStateSubscriber := newConnectivityStateSubscriber
11931198
newConnectivityStateSubscriber = func(delegate grpcsync.Subscriber) grpcsync.Subscriber {
1194-
wrappedSubscriber.delegate = delegate
1195-
return wrappedSubscriber
1199+
return &wrappingConnectivityStateSubscriber{
1200+
delegate: delegate,
1201+
connStateCh: wrappedSubscriber.connStateCh,
1202+
}
11961203
}
11971204
defer func() { newConnectivityStateSubscriber = origConnectivityStateSubscriber }()
11981205

balancer/rls/control_channel.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ type controlChannel struct {
6262
// hammering the RLS service while it is overloaded or down.
6363
throttler adaptiveThrottler
6464

65-
cc *grpc.ClientConn
66-
client rlsgrpc.RouteLookupServiceClient
67-
logger *internalgrpclog.PrefixLogger
68-
unsubscribe func()
69-
seenTransientFailure bool
65+
cc *grpc.ClientConn
66+
client rlsgrpc.RouteLookupServiceClient
67+
logger *internalgrpclog.PrefixLogger
68+
dropConnStateSubscriber func()
69+
seenTransientFailure bool
7070
}
7171

7272
// newControlChannel creates a controlChannel to rlsServerName and uses
@@ -90,7 +90,8 @@ func newControlChannel(rlsServerName, serviceConfig string, rpcTimeout time.Dura
9090
}
9191
// Subscribe to connectivity state before connecting to avoid missing initial
9292
// updates, which are only delivered to active subscribers.
93-
ctrlCh.unsubscribe = internal.SubscribeToConnectivityStateChanges.(func(cc *grpc.ClientConn, s grpcsync.Subscriber) func())(ctrlCh.cc, newConnectivityStateSubscriber(ctrlCh))
93+
subscribe := internal.SubscribeToConnectivityStateChanges.(func(cc *grpc.ClientConn, s grpcsync.Subscriber) func())
94+
ctrlCh.dropConnStateSubscriber = subscribe(ctrlCh.cc, newConnectivityStateSubscriber(ctrlCh))
9495
ctrlCh.cc.Connect()
9596
ctrlCh.client = rlsgrpc.NewRouteLookupServiceClient(ctrlCh.cc)
9697
ctrlCh.logger.Infof("Control channel created to RLS server at: %v", rlsServerName)
@@ -180,7 +181,7 @@ func (cc *controlChannel) dialOpts(bOpts balancer.BuildOptions, serviceConfig st
180181
}
181182

182183
func (cc *controlChannel) close() {
183-
cc.unsubscribe()
184+
cc.dropConnStateSubscriber()
184185
cc.cc.Close()
185186
cc.logger.Infof("Shutdown")
186187
}

0 commit comments

Comments
 (0)