Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: keep round_robin lb subchannel in TRANSIENT_FAILURE until becoming READY #6657

Merged
3 changes: 3 additions & 0 deletions core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java
Expand Up @@ -197,6 +197,9 @@ private void updateBalancingState() {

private void updateBalancingState(ConnectivityState state, RoundRobinPicker picker) {
if (state != currentState || !picker.isEquivalentTo(currentPicker)) {
if (currentState == TRANSIENT_FAILURE && state != READY) {
return;
voidzcy marked this conversation as resolved.
Show resolved Hide resolved
}
helper.updateBalancingState(state, picker);
currentState = state;
currentPicker = picker;
Expand Down
39 changes: 39 additions & 0 deletions core/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java
Expand Up @@ -294,6 +294,45 @@ public void pickAfterStateChange() throws Exception {
verifyNoMoreInteractions(mockHelper);
}

@Test
public void stayTransientFailureUntilReady() {
InOrder inOrder = inOrder(mockHelper);
loadBalancer.handleResolvedAddresses(
ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(Attributes.EMPTY)
.build());

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

for (Subchannel sc : loadBalancer.getSubchannels()) {
deliverSubchannelState(
sc,
ConnectivityStateInfo
.forTransientFailure(Status.UNKNOWN.withDescription("connection broken")));
}
inOrder.verify(mockHelper).updateBalancingState(eq(TRANSIENT_FAILURE), isA(EmptyPicker.class));

for (Subchannel sc : loadBalancer.getSubchannels()) {
deliverSubchannelState(
sc,
ConnectivityStateInfo.forNonError(IDLE));
}
inOrder.verifyNoMoreInteractions();

for (Subchannel sc : loadBalancer.getSubchannels()) {
deliverSubchannelState(
sc,
ConnectivityStateInfo.forNonError(CONNECTING));
}
inOrder.verifyNoMoreInteractions();

Subchannel subchannel = loadBalancer.getSubchannels().iterator().next();
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));
inOrder.verify(mockHelper).updateBalancingState(eq(READY), isA(ReadyPicker.class));

verify(mockHelper, times(3)).createSubchannel(any(CreateSubchannelArgs.class));
verifyNoMoreInteractions(mockHelper);
}

@Test
public void pickerRoundRobin() throws Exception {
Subchannel subchannel = mock(Subchannel.class);
Expand Down