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,8 +153,11 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
}
|
}
|
||||||
if (childLb != null) {
|
if (childLb != null) {
|
||||||
childLb.shutdown();
|
childLb.shutdown();
|
||||||
|
if (childLbHelper != null) {
|
||||||
|
childLbHelper.updateSslContextProviderSupplier(null);
|
||||||
childLbHelper = null;
|
childLbHelper = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (xdsClient != null) {
|
if (xdsClient != null) {
|
||||||
xdsClient = xdsClientPool.returnObject(xdsClient);
|
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.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
|
|
@ -100,6 +101,10 @@ public final class SslContextProviderSupplier implements Closeable {
|
||||||
: tlsContextManager.findOrCreateServerSslContextProvider((DownstreamTlsContext) tlsContext);
|
: tlsContextManager.findOrCreateServerSslContextProvider((DownstreamTlsContext) tlsContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting public boolean isShutdown() {
|
||||||
|
return shutdown;
|
||||||
|
}
|
||||||
|
|
||||||
/** Called by consumer when tlsContext changes. */
|
/** Called by consumer when tlsContext changes. */
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,9 @@ public class ClusterImplLoadBalancerTest {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
if (loadBalancer != null) {
|
||||||
loadBalancer.shutdown();
|
loadBalancer.shutdown();
|
||||||
|
}
|
||||||
assertThat(xdsClientRefs).isEqualTo(0);
|
assertThat(xdsClientRefs).isEqualTo(0);
|
||||||
assertThat(downstreamBalancers).isEmpty();
|
assertThat(downstreamBalancers).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
@ -553,11 +555,21 @@ public class ClusterImplLoadBalancerTest {
|
||||||
SslContextProviderSupplier supplier =
|
SslContextProviderSupplier supplier =
|
||||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||||
if (enableSecurity) {
|
if (enableSecurity) {
|
||||||
|
assertThat(supplier.isShutdown()).isFalse();
|
||||||
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
||||||
} else {
|
} else {
|
||||||
assertThat(supplier).isNull();
|
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,
|
private void deliverAddressesAndConfig(List<EquivalentAddressGroup> addresses,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue