mirror of https://github.com/grpc/grpc-java.git
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:
parent
ff59104b62
commit
389c5403e9
|
|
@ -1391,12 +1391,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
@Override
|
@Override
|
||||||
public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
|
public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
|
||||||
syncContext.throwIfNotInThisSynchronizationContext();
|
syncContext.throwIfNotInThisSynchronizationContext();
|
||||||
return createSubchannelInternal(args);
|
// No new subchannel should be created after load balancer has been shutdown.
|
||||||
}
|
checkState(!terminating, "Channel is being terminated");
|
||||||
|
|
||||||
private SubchannelImpl createSubchannelInternal(CreateSubchannelArgs args) {
|
|
||||||
// TODO(ejona): can we be even stricter? Like loadBalancer == null?
|
|
||||||
checkState(!terminated, "Channel is terminated");
|
|
||||||
return new SubchannelImpl(args, this);
|
return new SubchannelImpl(args, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1823,18 +1819,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
private void internalStart(final SubchannelStateListener listener) {
|
private void internalStart(final SubchannelStateListener listener) {
|
||||||
checkState(!started, "already started");
|
checkState(!started, "already started");
|
||||||
checkState(!shutdown, "already shutdown");
|
checkState(!shutdown, "already shutdown");
|
||||||
|
checkState(!terminating, "Channel is being terminated");
|
||||||
started = true;
|
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 {
|
final class ManagedInternalSubchannelCallback extends InternalSubchannel.Callback {
|
||||||
// All callbacks are run in syncContext
|
// All callbacks are run in syncContext
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue