Skip to content

Commit

Permalink
xds: Check for validity of xdsClient in ClusterImplLbHelper (grpc#11553)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
DNVindhya authored and kannanjgithub committed Oct 23, 2024
1 parent b1614e6 commit 990b341
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public void start(SubchannelStateListener listener) {
delegate().start(new SubchannelStateListener() {
@Override
public void onSubchannelState(ConnectivityStateInfo newState) {
if (newState.getState().equals(ConnectivityState.READY)) {
// Do nothing if LB has been shutdown
if (xdsClient != null && newState.getState().equals(ConnectivityState.READY)) {
// Get locality based on the connected address attributes
ClusterLocality updatedClusterLocality = createClusterLocalityFromAttributes(
subchannel.getConnectedAddressAttributes());
Expand Down

0 comments on commit 990b341

Please sign in to comment.