xds: fix NPE in wrr in TF state (#10868)

This commit is contained in:
yifeizhuang 2024-02-01 09:06:46 -08:00 committed by GitHub
parent c0a9d315d3
commit a97f21b61e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -378,6 +378,9 @@ final class WeightedRoundRobinLoadBalancer extends RoundRobinLoadBalancer {
WeightedChildLbState wChild = (WeightedChildLbState) childLbState; WeightedChildLbState wChild = (WeightedChildLbState) childLbState;
PickResult pickResult = childLbState.getCurrentPicker().pickSubchannel(args); PickResult pickResult = childLbState.getCurrentPicker().pickSubchannel(args);
Subchannel subchannel = pickResult.getSubchannel(); Subchannel subchannel = pickResult.getSubchannel();
if (subchannel == null) {
return pickResult;
}
if (!enableOobLoadReport) { if (!enableOobLoadReport) {
return PickResult.withSubchannel(subchannel, return PickResult.withSubchannel(subchannel,
OrcaPerRequestUtil.getInstance().newOrcaClientStreamTracerFactory( OrcaPerRequestUtil.getInstance().newOrcaClientStreamTracerFactory(

View File

@ -47,6 +47,7 @@ import io.grpc.LoadBalancer.ResolvedAddresses;
import io.grpc.LoadBalancer.Subchannel; import io.grpc.LoadBalancer.Subchannel;
import io.grpc.LoadBalancer.SubchannelPicker; import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancer.SubchannelStateListener; import io.grpc.LoadBalancer.SubchannelStateListener;
import io.grpc.Status;
import io.grpc.SynchronizationContext; import io.grpc.SynchronizationContext;
import io.grpc.internal.FakeClock; import io.grpc.internal.FakeClock;
import io.grpc.internal.TestUtils; import io.grpc.internal.TestUtils;
@ -162,6 +163,22 @@ public class WeightedRoundRobinLoadBalancerTest {
verify(helper, times(3)).createSubchannel(any(CreateSubchannelArgs.class)); verify(helper, times(3)).createSubchannel(any(CreateSubchannelArgs.class));
} }
@Test
public void pickChildLbTF() throws Exception {
syncContext.execute(() -> wrr.acceptResolvedAddresses(ResolvedAddresses.newBuilder()
.setAddresses(servers.subList(0, 1)).setLoadBalancingPolicyConfig(weightedConfig)
.setAttributes(affinity).build()));
Iterator<Subchannel> it = subchannels.values().iterator();
Subchannel readySubchannel1 = it.next();
getSubchannelStateListener(readySubchannel1).onSubchannelState(ConnectivityStateInfo
.forTransientFailure(Status.UNAVAILABLE));
verify(helper).updateBalancingState(
eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
final WeightedRoundRobinPicker weightedPicker =
(WeightedRoundRobinPicker) pickerCaptor.getValue();
weightedPicker.pickSubchannel(mockArgs);
}
@Test @Test
public void wrrLifeCycle() { public void wrrLifeCycle() {
syncContext.execute(() -> wrr.acceptResolvedAddresses(ResolvedAddresses.newBuilder() syncContext.execute(() -> wrr.acceptResolvedAddresses(ResolvedAddresses.newBuilder()