4545import io .grpc .netty .shaded .io .netty .handler .ssl .util .SelfSignedCertificate ;
4646import io .grpc .netty .shaded .io .netty .util .AsciiString ;
4747import io .grpc .netty .shaded .io .netty .util .CharsetUtil ;
48+ import io .grpc .netty .shaded .io .netty .util .ReferenceCountUtil ;
4849
4950import java .io .IOException ;
5051import java .io .InputStream ;
@@ -77,7 +78,7 @@ public class ProxyAndTlsProtocolNegotiator implements InternalProtocolNegotiator
7778 */
7879 private static final int SSL_RECORD_HEADER_LENGTH = 5 ;
7980
80- private static SslContext sslContext ;
81+ private static volatile SslContext sslContext ;
8182
8283 public ProxyAndTlsProtocolNegotiator () {
8384 try {
@@ -113,6 +114,7 @@ public static void loadSslContext() throws CertificateException, IOException {
113114 provider = SslProvider .JDK ;
114115 log .info ("Using JDK SSL provider" );
115116 }
117+ SslContext oldSslContext = sslContext ;
116118 if (proxyConfig .isTlsTestModeEnable ()) {
117119 SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate ();
118120 sslContext = GrpcSslContexts .forServer (selfSignedCertificate .certificate (), selfSignedCertificate .privateKey ())
@@ -136,6 +138,9 @@ public static void loadSslContext() throws CertificateException, IOException {
136138 .build ();
137139 }
138140 }
141+ if (oldSslContext != null ) {
142+ ReferenceCountUtil .release (oldSslContext );
143+ }
139144 }
140145
141146 private class ProxyAndTlsProtocolHandler extends ByteToMessageDecoder {
0 commit comments