mirror of https://github.com/grpc/grpc-java.git
xds: close SslContexrProviderSupplier when the CDS LoadBalancer is shut down to prevent leakage (#8240)
This commit is contained in:
parent
0c723f7ca9
commit
4209c8d8cc
|
|
@ -153,7 +153,10 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
|||
}
|
||||
if (childLb != null) {
|
||||
childLb.shutdown();
|
||||
childLbHelper = null;
|
||||
if (childLbHelper != null) {
|
||||
childLbHelper.updateSslContextProviderSupplier(null);
|
||||
childLbHelper = null;
|
||||
}
|
||||
}
|
||||
if (xdsClient != null) {
|
||||
xdsClient = xdsClientPool.returnObject(xdsClient);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.grpc.xds.internal.sds;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||
|
|
@ -100,6 +101,10 @@ public final class SslContextProviderSupplier implements Closeable {
|
|||
: tlsContextManager.findOrCreateServerSslContextProvider((DownstreamTlsContext) tlsContext);
|
||||
}
|
||||
|
||||
@VisibleForTesting public boolean isShutdown() {
|
||||
return shutdown;
|
||||
}
|
||||
|
||||
/** Called by consumer when tlsContext changes. */
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,9 @@ public class ClusterImplLoadBalancerTest {
|
|||
|
||||
@After
|
||||
public void tearDown() {
|
||||
loadBalancer.shutdown();
|
||||
if (loadBalancer != null) {
|
||||
loadBalancer.shutdown();
|
||||
}
|
||||
assertThat(xdsClientRefs).isEqualTo(0);
|
||||
assertThat(downstreamBalancers).isEmpty();
|
||||
}
|
||||
|
|
@ -553,11 +555,21 @@ public class ClusterImplLoadBalancerTest {
|
|||
SslContextProviderSupplier supplier =
|
||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||
if (enableSecurity) {
|
||||
assertThat(supplier.isShutdown()).isFalse();
|
||||
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
||||
} else {
|
||||
assertThat(supplier).isNull();
|
||||
}
|
||||
}
|
||||
loadBalancer.shutdown();
|
||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||
SslContextProviderSupplier supplier =
|
||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||
if (enableSecurity) {
|
||||
assertThat(supplier.isShutdown()).isTrue();
|
||||
}
|
||||
}
|
||||
loadBalancer = null;
|
||||
}
|
||||
|
||||
private void deliverAddressesAndConfig(List<EquivalentAddressGroup> addresses,
|
||||
|
|
|
|||
Loading…
Reference in New Issue