Skip to content

Commit b692b9d

Browse files
committedOct 16, 2024·
core: Handle NR/LB exceptions when panicking
If a panic is followed a panic, we'd ignore the second. But if an exception happens while entering panic mode we may fail to update the picker with the first error. This is "fine" from a correctness standpoint; all bets are off when panicking and we've already logged the first error. But failing RPCs can often be more easily seen than just the log. Noticed because of http://yaqs/8493785598685872128
1 parent 99f8683 commit b692b9d

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed
 

Diff for: ‎core/src/main/java/io/grpc/internal/ManagedChannelImpl.java

+10-24
Original file line numberDiff line numberDiff line change
@@ -779,30 +779,16 @@ void panic(final Throwable t) {
779779
return;
780780
}
781781
panicMode = true;
782-
cancelIdleTimer(/* permanent= */ true);
783-
shutdownNameResolverAndLoadBalancer(false);
784-
final class PanicSubchannelPicker extends SubchannelPicker {
785-
private final PickResult panicPickResult =
786-
PickResult.withDrop(
787-
Status.INTERNAL.withDescription("Panic! This is a bug!").withCause(t));
788-
789-
@Override
790-
public PickResult pickSubchannel(PickSubchannelArgs args) {
791-
return panicPickResult;
792-
}
793-
794-
@Override
795-
public String toString() {
796-
return MoreObjects.toStringHelper(PanicSubchannelPicker.class)
797-
.add("panicPickResult", panicPickResult)
798-
.toString();
799-
}
782+
try {
783+
cancelIdleTimer(/* permanent= */ true);
784+
shutdownNameResolverAndLoadBalancer(false);
785+
} finally {
786+
updateSubchannelPicker(new LoadBalancer.FixedResultPicker(PickResult.withDrop(
787+
Status.INTERNAL.withDescription("Panic! This is a bug!").withCause(t))));
788+
realChannel.updateConfigSelector(null);
789+
channelLogger.log(ChannelLogLevel.ERROR, "PANIC! Entering TRANSIENT_FAILURE");
790+
channelStateManager.gotoState(TRANSIENT_FAILURE);
800791
}
801-
802-
updateSubchannelPicker(new PanicSubchannelPicker());
803-
realChannel.updateConfigSelector(null);
804-
channelLogger.log(ChannelLogLevel.ERROR, "PANIC! Entering TRANSIENT_FAILURE");
805-
channelStateManager.gotoState(TRANSIENT_FAILURE);
806792
}
807793

808794
@VisibleForTesting
@@ -1404,7 +1390,7 @@ public void updateBalancingState(
14041390
final class UpdateBalancingState implements Runnable {
14051391
@Override
14061392
public void run() {
1407-
if (LbHelperImpl.this != lbHelper) {
1393+
if (LbHelperImpl.this != lbHelper || panicMode) {
14081394
return;
14091395
}
14101396
updateSubchannelPicker(newPicker);

0 commit comments

Comments
 (0)
Please sign in to comment.