Skip to content

Commit

Permalink
core: make subchannel creation timing restriction stricter (#7790)
Browse files Browse the repository at this point in the history
Throw for subchannel creation if the channel is being shutting down and the delayed transport is terminated (aka, all retry calls has been finished). This enforces load balancer implementations to avoid creating subchannels after being shut down.
  • Loading branch information
voidzcy committed Jan 14, 2021
1 parent ff59104 commit 389c540
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Expand Up @@ -1391,12 +1391,8 @@ private class LbHelperImpl extends LoadBalancer.Helper {
@Override
public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
syncContext.throwIfNotInThisSynchronizationContext();
return createSubchannelInternal(args);
}

private SubchannelImpl createSubchannelInternal(CreateSubchannelArgs args) {
// TODO(ejona): can we be even stricter? Like loadBalancer == null?
checkState(!terminated, "Channel is terminated");
// No new subchannel should be created after load balancer has been shutdown.
checkState(!terminating, "Channel is being terminated");
return new SubchannelImpl(args, this);
}

Expand Down Expand Up @@ -1823,18 +1819,8 @@ private final class SubchannelImpl extends AbstractSubchannel {
private void internalStart(final SubchannelStateListener listener) {
checkState(!started, "already started");
checkState(!shutdown, "already shutdown");
checkState(!terminating, "Channel is being terminated");
started = true;
// TODO(zhangkun): possibly remove the volatile of terminating when this whole method is
// required to be called from syncContext
if (terminating) {
syncContext.execute(new Runnable() {
@Override
public void run() {
listener.onSubchannelState(ConnectivityStateInfo.forNonError(SHUTDOWN));
}
});
return;
}
final class ManagedInternalSubchannelCallback extends InternalSubchannel.Callback {
// All callbacks are run in syncContext
@Override
Expand Down

0 comments on commit 389c540

Please sign in to comment.