Skip to content

Commit fa36269

Browse files
authored
xds: fix NPE in wrr in TF state (grpc#10874)
1 parent c83e5f9 commit fa36269

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
@@ -365,6 +365,9 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
365365
WeightedChildLbState wChild = (WeightedChildLbState) childLbState;
366366
PickResult pickResult = childLbState.getCurrentPicker().pickSubchannel(args);
367367
Subchannel subchannel = pickResult.getSubchannel();
368+
if (subchannel == null) {
369+
return pickResult;
370+
}
368371
if (!enableOobLoadReport) {
369372
return PickResult.withSubchannel(subchannel,
370373
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)