Skip to content

Commit

Permalink
xds: Check for validity of xdsClient in ClusterImplLbHelper (#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 Sep 24, 2024
1 parent c92453f commit 3e8ef8c
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 @@ -236,7 +236,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 3e8ef8c

Please sign in to comment.