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

grpclb: fix pick_first mode shutdown without subchannels. #6072

Merged
merged 2 commits into from Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
Expand Up @@ -341,8 +341,10 @@ void shutdown() {
subchannelPool.clear();
break;
case PICK_FIRST:
checkState(subchannels.size() == 1, "Excessive Subchannels: %s", subchannels);
subchannels.values().iterator().next().shutdown();
if (!subchannels.isEmpty()) {
checkState(subchannels.size() == 1, "Excessive Subchannels: %s", subchannels);
subchannels.values().iterator().next().shutdown();
}
break;
default:
throw new AssertionError("Missing case for " + mode);
Expand Down
25 changes: 25 additions & 0 deletions grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Expand Up @@ -1813,6 +1813,31 @@ public void grpclbWorking_pickFirstMode() throws Exception {
.returnSubchannel(any(Subchannel.class), any(ConnectivityStateInfo.class));
}

@Test
public void shutdownWithoutSubchannel_roundRobin() throws Exception {
subtestShutdownWithoutSubchannel("round_robin");
}

@Test
public void shutdownWithoutSubchannel_pickFirst() throws Exception {
subtestShutdownWithoutSubchannel("pick_first");
}

private void subtestShutdownWithoutSubchannel(String childPolicy) throws Exception {
String lbConfig = "{\"childPolicy\" : [ {\"" + childPolicy + "\" : {}} ]}";
List<EquivalentAddressGroup> grpclbResolutionList = createResolvedServerAddresses(true);
Attributes grpclbResolutionAttrs = Attributes.newBuilder().set(
LoadBalancer.ATTR_LOAD_BALANCING_CONFIG, parseJsonObject(lbConfig)).build();
deliverResolvedAddresses(grpclbResolutionList, grpclbResolutionAttrs);
verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
assertEquals(1, lbRequestObservers.size());
StreamObserver<LoadBalanceRequest> requestObserver = lbRequestObservers.poll();

verify(requestObserver, never()).onCompleted();
balancer.shutdown();
verify(requestObserver).onCompleted();
}

@SuppressWarnings("deprecation")
@Test
public void grpclbWorking_pickFirstMode_expectBackendsShuffled() throws Exception {
Expand Down