Skip to content

Commit

Permalink
grpclb: cache requestConnection if no subchannel created
Browse files Browse the repository at this point in the history
An issue was found during CBT RLS client testing: The RLS lb creates grplb child balancer, calls `grpclb.handleResolvedAddress()` then immediately calls `grpclb.requestConnection()`. The subchannel in `GrpclbState.currentPicker.pickList` contains only `GrpclbState.BUFFER_ENTRY` at the moment `grpclb.requestConnection()` is called, and therefore the `requestConnection()` is no-op, and RPC is hanging.
  • Loading branch information
dapengzhang0 committed Sep 16, 2020
1 parent 80f6d87 commit 3abdb28
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
Expand Up @@ -158,6 +158,7 @@ enum Mode {
private List<BackendEntry> backendList = Collections.emptyList();
private RoundRobinPicker currentPicker =
new RoundRobinPicker(Collections.<DropEntry>emptyList(), Arrays.asList(BUFFER_ENTRY));
private boolean requestConnectionPending;

GrpclbState(
GrpclbConfig config,
Expand Down Expand Up @@ -242,9 +243,11 @@ void handleAddresses(
}

void requestConnection() {
requestConnectionPending = true;
for (RoundRobinEntry entry : currentPicker.pickList) {
if (entry instanceof IdleSubchannelEntry) {
((IdleSubchannelEntry) entry).subchannel.requestConnection();
requestConnectionPending = false;
}
}
}
Expand Down Expand Up @@ -471,6 +474,10 @@ public void onSubchannelState(ConnectivityStateInfo newState) {
handleSubchannelState(subchannel, newState);
}
});
if (requestConnectionPending) {
subchannel.requestConnection();
requestConnectionPending = false;
}
} else {
subchannel = subchannels.values().iterator().next();
subchannel.updateAddresses(eagList);
Expand Down

0 comments on commit 3abdb28

Please sign in to comment.