core: make subchannel creation timing restriction stricter (#7790)

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.
This commit is contained in:
Chengyuan Zhang 2021-01-13 17:01:02 -08:00 committed by GitHub
parent ff59104b62
commit 389c5403e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 17 deletions

View File

@ -1391,12 +1391,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
@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);
}
@ -1823,18 +1819,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
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