Skip to content

Commit 67cab18

Browse files
authored
xds: Check for validity of xdsClient in ClusterImplLbHelper (#11553) (#11554)
* Added null check for xdsClient in onSubChannelState. This avoids NPE for xdsClient when LB is shutdown and onSubChannelState is called later as part of listener callback. As shutdown is racy and eventually consistent, this check would avoid calculating locality after LB is shutdown.
1 parent a475cfa commit 67cab18

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ public void start(SubchannelStateListener listener) {
236236
delegate().start(new SubchannelStateListener() {
237237
@Override
238238
public void onSubchannelState(ConnectivityStateInfo newState) {
239-
if (newState.getState().equals(ConnectivityState.READY)) {
239+
// Do nothing if LB has been shutdown
240+
if (xdsClient != null && newState.getState().equals(ConnectivityState.READY)) {
240241
// Get locality based on the connected address attributes
241242
ClusterLocality updatedClusterLocality = createClusterLocalityFromAttributes(
242243
subchannel.getConnectedAddressAttributes());

0 commit comments

Comments
 (0)