Skip to content

Commit 4914ffc

Browse files
committed
core: Avoid exception handling in PF for invalid index
It is trivial to avoid the exception from addressIndex.getCurrentAddress(). The log message was inaccurate, as the subchannel might have been TRANSIENT_FAILURE. The only important part of the condition was whether the subchannel was the current subchannel.
1 parent 33687d3 commit 4914ffc

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

core/src/main/java/io/grpc/internal/PickFirstLeafLoadBalancer.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,9 @@ public void onSubchannelState(ConnectivityStateInfo newState) {
482482
log.log(Level.FINE, "Received health status {0} for subchannel {1}",
483483
new Object[]{newState, subchannelData.subchannel});
484484
subchannelData.healthStateInfo = newState;
485-
try {
486-
if (subchannelData == subchannels.get(addressIndex.getCurrentAddress())) {
487-
updateHealthCheckedState(subchannelData);
488-
}
489-
} catch (IllegalStateException e) {
490-
log.fine("Health listener received state change after subchannel was removed");
485+
if (addressIndex.isValid()
486+
&& subchannelData == subchannels.get(addressIndex.getCurrentAddress())) {
487+
updateHealthCheckedState(subchannelData);
491488
}
492489
}
493490
}

0 commit comments

Comments
 (0)