Skip to content

Commit 1abdaf3

Browse files
authored
xds: fix NPE in wrr in TF state (grpc#10875)
1 parent 529d0ab commit 1abdaf3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
378378
WeightedChildLbState wChild = (WeightedChildLbState) childLbState;
379379
PickResult pickResult = childLbState.getCurrentPicker().pickSubchannel(args);
380380
Subchannel subchannel = pickResult.getSubchannel();
381+
if (subchannel == null) {
382+
return pickResult;
383+
}
381384
if (!enableOobLoadReport) {
382385
return PickResult.withSubchannel(subchannel,
383386
OrcaPerRequestUtil.getInstance().newOrcaClientStreamTracerFactory(

xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import io.grpc.LoadBalancer.Subchannel;
4848
import io.grpc.LoadBalancer.SubchannelPicker;
4949
import io.grpc.LoadBalancer.SubchannelStateListener;
50+
import io.grpc.Status;
5051
import io.grpc.SynchronizationContext;
5152
import io.grpc.internal.FakeClock;
5253
import io.grpc.internal.TestUtils;
@@ -162,6 +163,22 @@ public ClientCall<OrcaLoadReportRequest, OrcaLoadReport> answer(
162163
verify(helper, times(3)).createSubchannel(any(CreateSubchannelArgs.class));
163164
}
164165

166+
@Test
167+
public void pickChildLbTF() throws Exception {
168+
syncContext.execute(() -> wrr.acceptResolvedAddresses(ResolvedAddresses.newBuilder()
169+
.setAddresses(servers.subList(0, 1)).setLoadBalancingPolicyConfig(weightedConfig)
170+
.setAttributes(affinity).build()));
171+
Iterator<Subchannel> it = subchannels.values().iterator();
172+
Subchannel readySubchannel1 = it.next();
173+
getSubchannelStateListener(readySubchannel1).onSubchannelState(ConnectivityStateInfo
174+
.forTransientFailure(Status.UNAVAILABLE));
175+
verify(helper).updateBalancingState(
176+
eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
177+
final WeightedRoundRobinPicker weightedPicker =
178+
(WeightedRoundRobinPicker) pickerCaptor.getValue();
179+
weightedPicker.pickSubchannel(mockArgs);
180+
}
181+
165182
@Test
166183
public void wrrLifeCycle() {
167184
syncContext.execute(() -> wrr.acceptResolvedAddresses(ResolvedAddresses.newBuilder()

0 commit comments

Comments
 (0)