grpclb: cache requestConnection if no subchannel created
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.
diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
index b6c9913..3630db6 100644
--- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
+++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
@@ -158,6 +158,7 @@
private List<BackendEntry> backendList = Collections.emptyList();
private RoundRobinPicker currentPicker =
new RoundRobinPicker(Collections.<DropEntry>emptyList(), Arrays.asList(BUFFER_ENTRY));
+ private boolean requestConnectionPending;
GrpclbState(
GrpclbConfig config,
@@ -242,9 +243,11 @@
}
void requestConnection() {
+ requestConnectionPending = true;
for (RoundRobinEntry entry : currentPicker.pickList) {
if (entry instanceof IdleSubchannelEntry) {
((IdleSubchannelEntry) entry).subchannel.requestConnection();
+ requestConnectionPending = false;
}
}
}
@@ -471,6 +474,10 @@
handleSubchannelState(subchannel, newState);
}
});
+ if (requestConnectionPending) {
+ subchannel.requestConnection();
+ requestConnectionPending = false;
+ }
} else {
subchannel = subchannels.values().iterator().next();
subchannel.updateAddresses(eagList);