GeezerVison is showing github.com — Auto-port 5.0: Weakly reference engines from the OpenSSL engine map (… · netty/netty@e954354
File treeExpand file treeCollapse file tree Open diff view settings main/java/io/netty/handler/ssl test/java/io/netty/handler/ssl
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/OpenSslClientSessionCache.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 31 | 31 | final class OpenSslClientSessionCache extends OpenSslSessionCache { | 32 | 32 | private final Map<HostPort, Set<NativeSslSession>> sessions = new HashMap<>(); | 33 | 33 |
| 34 | | - OpenSslClientSessionCache(Map<Long, ReferenceCountedOpenSslEngine> engines) { | | 34 | + OpenSslClientSessionCache(OpenSslEngineMap engines) { | 35 | 35 | super(engines); | 36 | 36 | } | 37 | 37 |
| |
Collapse file Copy file name to clipboard +61Lines changed: 61 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/* | | 2 | + * Copyright 2026 The Netty Project | | 3 | + * | | 4 | + * The Netty Project licenses this file to you under the Apache License, | | 5 | + * version 2.0 (the "License"); you may not use this file except in compliance | | 6 | + * with the License. You may obtain a copy of the License at: | | 7 | + * | | 8 | + * https://www.apache.org/licenses/LICENSE-2.0 | | 9 | + * | | 10 | + * Unless required by applicable law or agreed to in writing, software | | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | | 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | | 13 | + * License for the specific language governing permissions and limitations | | 14 | + * under the License. | | 15 | + */ | | 16 | +package io.netty.handler.ssl; | | 17 | + | | 18 | +import java.lang.ref.WeakReference; | | 19 | +import java.util.Map; | | 20 | +import java.util.concurrent.ConcurrentHashMap; | | 21 | + | | 22 | +/** | | 23 | + * Maps a native {@code SSL*} pointer to its {@link ReferenceCountedOpenSslEngine} so native OpenSSL callbacks | | 24 | + * (certificate verification, private-key operations, certificate (de)compression) can recover the engine from the | | 25 | + * raw pointer they are handed. | | 26 | + * <p> | | 27 | + * Engines are held weakly so a leaked engine is not pinned by the long-lived parent | | 28 | + * {@link ReferenceCountedOpenSslContext} (a live engine is always strongly reachable via its {@link SslHandler}, and | | 29 | + * on the stack during a callback, so weak retention never collects a usable one). For {@link SslProvider#OPENSSL} | | 30 | + * this lets {@link OpenSslEngine#finalize()} reclaim the native {@code SSL*} without waiting for the whole context to | | 31 | + * be collected; a leaked {@link SslProvider#OPENSSL_REFCNT} engine has no finalizer so its native memory still leaks, | | 32 | + * but it becomes collectable and so is reported by the {@code ResourceLeakDetector} rather than pinned silently. | | 33 | + * <p> | | 34 | + * Entries are removed in {@link ReferenceCountedOpenSslEngine#shutdown()}, so the map does not grow in steady state. | | 35 | + * A cleared {@link WeakReference} lingers only for a leaked {@code OPENSSL_REFCNT} engine (whose {@code SSL*} is never | | 36 | + * freed, hence never reused); such a husk is tiny, dwarfed by the native memory it marks, and is deliberately left as | | 37 | + * a heap-inspectable leak signal. Do not reap it (e.g. via a {@code ReferenceQueue}): {@link #get(long)} already | | 38 | + * yields {@code null} for a cleared reference, so reaping would only erase that signal. | | 39 | + */ | | 40 | +final class OpenSslEngineMap { | | 41 | + | | 42 | + private final Map<Long, WeakReference<ReferenceCountedOpenSslEngine>> engines = | | 43 | + new ConcurrentHashMap<Long, WeakReference<ReferenceCountedOpenSslEngine>>(); | | 44 | + | | 45 | + void add(long ssl, ReferenceCountedOpenSslEngine engine) { | | 46 | + // A fresh SSL_new() pointer maps to nothing yet: an SSL* is reused only after shutdown() removed its entry | | 47 | + // (remove-before-freeSSL), and a husk survives only for a never-freed, never-reused SSL*. | | 48 | + WeakReference<ReferenceCountedOpenSslEngine> prev = | | 49 | + engines.put(ssl, new WeakReference<ReferenceCountedOpenSslEngine>(engine)); | | 50 | + assert prev == null : "OpenSslEngineMap already had an entry for SSL* 0x" + Long.toHexString(ssl); | | 51 | + } | | 52 | + | | 53 | + void remove(long ssl) { | | 54 | + engines.remove(ssl); | | 55 | + } | | 56 | + | | 57 | + ReferenceCountedOpenSslEngine get(long ssl) { | | 58 | + WeakReference<ReferenceCountedOpenSslEngine> ref = engines.get(ssl); | | 59 | + return ref == null ? null : ref.get(); | | 60 | + } | | 61 | +} |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/OpenSslSessionCache.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,7 @@ class OpenSslSessionCache implements SSLSessionCache { | 49 | 49 | DEFAULT_CACHE_SIZE = 20480; | 50 | 50 | } | 51 | 51 | } | 52 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 52 | + private final OpenSslEngineMap engines; | 53 | 53 |
| 54 | 54 | private final Map<OpenSslSessionId, NativeSslSession> sessions = | 55 | 55 | new LinkedHashMap<OpenSslSessionId, NativeSslSession>() { | @@ -74,7 +74,7 @@ protected boolean removeEldestEntry(Map.Entry<OpenSslSessionId, NativeSslSession | 74 | 74 | private final AtomicInteger sessionTimeout = new AtomicInteger(300); | 75 | 75 | private int sessionCounter; | 76 | 76 |
| 77 | | - OpenSslSessionCache(Map<Long, ReferenceCountedOpenSslEngine> engines) { | | 77 | + OpenSslSessionCache(OpenSslEngineMap engines) { | 78 | 78 | this.engines = engines; | 79 | 79 | } | 80 | 80 |
| |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslClientContext.java +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -103,7 +103,7 @@ public OpenSslSessionContext sessionContext() { | 103 | 103 | } | 104 | 104 |
| 105 | 105 | static OpenSslSessionContext newSessionContext(ReferenceCountedOpenSslContext thiz, long ctx, | 106 | | - Map<Long, ReferenceCountedOpenSslEngine> engines, | | 106 | + OpenSslEngineMap engines, | 107 | 107 | X509Certificate[] trustCertCollection, | 108 | 108 | TrustManagerFactory trustManagerFactory, | 109 | 109 | X509Certificate[] keyCertChain, PrivateKey key, | @@ -213,7 +213,7 @@ static OpenSslSessionContext newSessionContext(ReferenceCountedOpenSslContext th | 213 | 213 | } | 214 | 214 |
| 215 | 215 | private static void setVerifyCallback(long ctx, | 216 | | - Map<Long, ReferenceCountedOpenSslEngine> engines, | | 216 | + OpenSslEngineMap engines, | 217 | 217 | X509TrustManager manager) { | 218 | 218 | // Use this to prevent an error when running on java < 7 | 219 | 219 | if (useExtendedTrustManager(manager)) { | @@ -233,7 +233,7 @@ static final class OpenSslClientSessionContext extends OpenSslSessionContext { | 233 | 233 | private static final class TrustManagerVerifyCallback extends AbstractCertificateVerifier { | 234 | 234 | private final X509TrustManager manager; | 235 | 235 |
| 236 | | - TrustManagerVerifyCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, X509TrustManager manager) { | | 236 | + TrustManagerVerifyCallback(OpenSslEngineMap engines, X509TrustManager manager) { | 237 | 237 | super(engines); | 238 | 238 | this.manager = manager; | 239 | 239 | } | @@ -248,7 +248,7 @@ void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts, S | 248 | 248 | private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier { | 249 | 249 | private final X509ExtendedTrustManager manager; | 250 | 250 |
| 251 | | - ExtendedTrustManagerVerifyCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 251 | + ExtendedTrustManagerVerifyCallback(OpenSslEngineMap engines, | 252 | 252 | X509ExtendedTrustManager manager) { | 253 | 253 | super(engines); | 254 | 254 | this.manager = manager; | @@ -262,10 +262,10 @@ void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts, S | 262 | 262 | } | 263 | 263 |
| 264 | 264 | private static final class OpenSslClientCertificateCallback implements CertificateCallback { | 265 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 265 | + private final OpenSslEngineMap engines; | 266 | 266 | private final OpenSslKeyMaterialManager keyManagerHolder; | 267 | 267 |
| 268 | | - OpenSslClientCertificateCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 268 | + OpenSslClientCertificateCallback(OpenSslEngineMap engines, | 269 | 269 | OpenSslKeyMaterialManager keyManagerHolder) { | 270 | 270 | this.engines = engines; | 271 | 271 | this.keyManagerHolder = keyManagerHolder; | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslContext.java +10-12Lines changed: 10 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 57 | 57 | import java.util.List; | 58 | 58 | import java.util.Map; | 59 | 59 | import java.util.Set; | 60 | | -import java.util.concurrent.ConcurrentHashMap; | 61 | | -import java.util.concurrent.ConcurrentMap; | 62 | 60 | import java.util.concurrent.Executor; | 63 | 61 | import java.util.concurrent.locks.Lock; | 64 | 62 | import java.util.concurrent.locks.ReadWriteLock; | @@ -170,7 +168,7 @@ protected void deallocate() { | 170 | 168 | final boolean hasTmpDhKeys; | 171 | 169 | final String[] groups; | 172 | 170 | final boolean enableOcsp; | 173 | | - final ConcurrentMap<Long, ReferenceCountedOpenSslEngine> engines = new ConcurrentHashMap<>(); | | 171 | + final OpenSslEngineMap engines = new OpenSslEngineMap(); | 174 | 172 | final ReadWriteLock ctxLock = new ReentrantReadWriteLock(); | 175 | 173 | final List<OpenSslCredential> credentials = new ArrayList<>(); | 176 | 174 |
| @@ -880,9 +878,9 @@ public final boolean release(int decrement) { | 880 | 878 | } | 881 | 879 |
| 882 | 880 | abstract static class AbstractCertificateVerifier extends CertificateVerifier { | 883 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 881 | + private final OpenSslEngineMap engines; | 884 | 882 |
| 885 | | - AbstractCertificateVerifier(Map<Long, ReferenceCountedOpenSslEngine> engines) { | | 883 | + AbstractCertificateVerifier(OpenSslEngineMap engines) { | 886 | 884 | this.engines = engines; | 887 | 885 | } | 888 | 886 |
| @@ -1147,7 +1145,7 @@ static OpenSslKeyMaterialProvider setupSecurityProviderSignatureSource( | 1147 | 1145 | } | 1148 | 1146 | } | 1149 | 1147 |
| 1150 | | - private static ReferenceCountedOpenSslEngine retrieveEngine(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 1148 | + private static ReferenceCountedOpenSslEngine retrieveEngine(OpenSslEngineMap engines, | 1151 | 1149 | long ssl) | 1152 | 1150 | throws SSLException { | 1153 | 1151 | ReferenceCountedOpenSslEngine engine = engines.get(ssl); | @@ -1160,9 +1158,9 @@ private static ReferenceCountedOpenSslEngine retrieveEngine(Map<Long, ReferenceC | 1160 | 1158 |
| 1161 | 1159 | private static final class PrivateKeyMethod implements SSLPrivateKeyMethod { | 1162 | 1160 |
| 1163 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 1161 | + private final OpenSslEngineMap engines; | 1164 | 1162 | private final OpenSslPrivateKeyMethod keyMethod; | 1165 | | - PrivateKeyMethod(Map<Long, ReferenceCountedOpenSslEngine> engines, OpenSslPrivateKeyMethod keyMethod) { | | 1163 | + PrivateKeyMethod(OpenSslEngineMap engines, OpenSslPrivateKeyMethod keyMethod) { | 1166 | 1164 | this.engines = engines; | 1167 | 1165 | this.keyMethod = keyMethod; | 1168 | 1166 | } | @@ -1192,10 +1190,10 @@ public byte[] decrypt(long ssl, byte[] input) throws Exception { | 1192 | 1190 |
| 1193 | 1191 | private static final class AsyncPrivateKeyMethod implements AsyncSSLPrivateKeyMethod { | 1194 | 1192 |
| 1195 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 1193 | + private final OpenSslEngineMap engines; | 1196 | 1194 | private final OpenSslAsyncPrivateKeyMethod keyMethod; | 1197 | 1195 |
| 1198 | | - AsyncPrivateKeyMethod(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 1196 | + AsyncPrivateKeyMethod(OpenSslEngineMap engines, | 1199 | 1197 | OpenSslAsyncPrivateKeyMethod keyMethod) { | 1200 | 1198 | this.engines = engines; | 1201 | 1199 | this.keyMethod = keyMethod; | @@ -1261,10 +1259,10 @@ private static byte[] verifyResult(byte[] result) throws SignatureException { | 1261 | 1259 | } | 1262 | 1260 |
| 1263 | 1261 | private static final class CompressionAlgorithm implements CertificateCompressionAlgo { | 1264 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 1262 | + private final OpenSslEngineMap engines; | 1265 | 1263 | private final OpenSslCertificateCompressionAlgorithm compressionAlgorithm; | 1266 | 1264 |
| 1267 | | - CompressionAlgorithm(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 1265 | + CompressionAlgorithm(OpenSslEngineMap engines, | 1268 | 1266 | OpenSslCertificateCompressionAlgorithm compressionAlgorithm) { | 1269 | 1267 | this.engines = engines; | 1270 | 1268 | this.compressionAlgorithm = compressionAlgorithm; | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,7 +205,7 @@ protected void deallocate() { | 205 | 205 | final boolean jdkCompatibilityMode; | 206 | 206 | private final boolean clientMode; | 207 | 207 | final ByteBufAllocator alloc; | 208 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 208 | + private final OpenSslEngineMap engines; | 209 | 209 | private final OpenSslApplicationProtocolNegotiator apn; | 210 | 210 | private final ReferenceCountedOpenSslContext parentContext; | 211 | 211 | private final OpenSslInternalSession session; | @@ -422,8 +422,8 @@ public List<byte[]> getStatusResponses() { | 422 | 422 | // object so we need to retain a reference to the parent context. | 423 | 423 | parentContext = context; | 424 | 424 |
| 425 | | - // Adding the OpenSslEngine to the OpenSslEngineMap so it can be used in the AbstractCertificateVerifier. | 426 | | - engines.put(ssl, this); | | 425 | + // Register for the SSL* -> engine reverse lookup used by native callbacks; held weakly (see OpenSslEngineMap). | | 426 | + engines.add(ssl, this); | 427 | 427 |
| 428 | 428 | // Only create the leak after everything else was executed and so ensure we don't produce a false-positive for | 429 | 429 | // the ResourceLeakDetector. | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslServerContext.java +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,7 +98,7 @@ public OpenSslServerSessionContext sessionContext() { | 98 | 98 | } | 99 | 99 |
| 100 | 100 | static OpenSslServerSessionContext newSessionContext(ReferenceCountedOpenSslContext thiz, long ctx, | 101 | | - Map<Long, ReferenceCountedOpenSslEngine> engines, | | 101 | + OpenSslEngineMap engines, | 102 | 102 | X509Certificate[] trustCertCollection, | 103 | 103 | TrustManagerFactory trustManagerFactory, | 104 | 104 | X509Certificate[] keyCertChain, PrivateKey key, | @@ -217,7 +217,7 @@ static OpenSslServerSessionContext newSessionContext(ReferenceCountedOpenSslCont | 217 | 217 | } | 218 | 218 |
| 219 | 219 | private static void setVerifyCallback(long ctx, | 220 | | - Map<Long, ReferenceCountedOpenSslEngine> engines, | | 220 | + OpenSslEngineMap engines, | 221 | 221 | X509TrustManager manager) { | 222 | 222 | // Use this to prevent an error when running on java < 7 | 223 | 223 | if (useExtendedTrustManager(manager)) { | @@ -229,10 +229,10 @@ private static void setVerifyCallback(long ctx, | 229 | 229 | } | 230 | 230 |
| 231 | 231 | private static final class OpenSslServerCertificateCallback implements CertificateCallback { | 232 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 232 | + private final OpenSslEngineMap engines; | 233 | 233 | private final OpenSslKeyMaterialManager keyManagerHolder; | 234 | 234 |
| 235 | | - OpenSslServerCertificateCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 235 | + OpenSslServerCertificateCallback(OpenSslEngineMap engines, | 236 | 236 | OpenSslKeyMaterialManager keyManagerHolder) { | 237 | 237 | this.engines = engines; | 238 | 238 | this.keyManagerHolder = keyManagerHolder; | @@ -263,7 +263,7 @@ public void handle(long ssl, byte[] keyTypeBytes, byte[][] asn1DerEncodedPrincip | 263 | 263 | private static final class TrustManagerVerifyCallback extends AbstractCertificateVerifier { | 264 | 264 | private final X509TrustManager manager; | 265 | 265 |
| 266 | | - TrustManagerVerifyCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 266 | + TrustManagerVerifyCallback(OpenSslEngineMap engines, | 267 | 267 | X509TrustManager manager) { | 268 | 268 | super(engines); | 269 | 269 | this.manager = manager; | @@ -279,7 +279,7 @@ void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts, S | 279 | 279 | private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier { | 280 | 280 | private final X509ExtendedTrustManager manager; | 281 | 281 |
| 282 | | - ExtendedTrustManagerVerifyCallback(Map<Long, ReferenceCountedOpenSslEngine> engines, | | 282 | + ExtendedTrustManagerVerifyCallback(OpenSslEngineMap engines, | 283 | 283 | X509ExtendedTrustManager manager) { | 284 | 284 | super(engines); | 285 | 285 | this.manager = manager; | @@ -293,9 +293,9 @@ void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts, S | 293 | 293 | } | 294 | 294 |
| 295 | 295 | private static final class OpenSslSniHostnameMatcher implements SniHostNameMatcher { | 296 | | - private final Map<Long, ReferenceCountedOpenSslEngine> engines; | | 296 | + private final OpenSslEngineMap engines; | 297 | 297 |
| 298 | | - OpenSslSniHostnameMatcher(Map<Long, ReferenceCountedOpenSslEngine> engines) { | | 298 | + OpenSslSniHostnameMatcher(OpenSslEngineMap engines) { | 299 | 299 | this.engines = engines; | 300 | 300 | } | 301 | 301 |
| |
Collapse file Copy file name to clipboardExpand all lines: handler/src/test/java/io/netty/handler/ssl/OpenSslEngineTest.java +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 | import org.junit.jupiter.api.AfterEach; | 34 | 34 | import org.junit.jupiter.api.BeforeAll; | 35 | 35 | import org.junit.jupiter.api.Test; | | 36 | +import org.junit.jupiter.api.Timeout; | 36 | 37 | import org.junit.jupiter.api.condition.EnabledIf; | 37 | 38 | import org.junit.jupiter.api.extension.ExtendWith; | 38 | 39 | import org.junit.jupiter.api.function.Executable; | | 55 | 56 | import java.util.List; | 56 | 57 | import java.util.Set; | 57 | 58 | import java.util.concurrent.ThreadLocalRandom; | | 59 | +import java.util.concurrent.TimeUnit; | 58 | 60 | import javax.crypto.Cipher; | 59 | 61 | import javax.crypto.spec.IvParameterSpec; | 60 | 62 | import javax.crypto.spec.SecretKeySpec; | @@ -1515,6 +1517,39 @@ public void execute() throws Throwable { | 1515 | 1517 | } | 1516 | 1518 | } | 1517 | 1519 |
| | 1520 | + // Pins OPENSSL (not sslClientProvider()) because only the OPENSSL engine has a finalizer to drive the reclaim | | 1521 | + // asserted here; the OPENSSL_REFCNT subclass overrides this to a no-op (it has no finalizer). Verifies that a | | 1522 | + // leaked engine is collected and releases its parent context while the context is still alive -- only possible | | 1523 | + // because OpenSslEngineMap holds engines weakly rather than pinning them for the context's lifetime. | | 1524 | + @Test | | 1525 | + @Timeout(value = 30, unit = TimeUnit.SECONDS) | | 1526 | + public void leakedEngineIsReclaimedWhileContextAlive() throws Exception { | | 1527 | + assumeTrue(OpenSsl.isAvailable()); | | 1528 | + | | 1529 | + SslContext ctx = SslContextBuilder.forClient() | | 1530 | + .trustManager(InsecureTrustManagerFactory.INSTANCE) | | 1531 | + .sslProvider(OPENSSL) | | 1532 | + .build(); | | 1533 | + try { | | 1534 | + // newEngine retains the context, so its refCnt goes from 1 to 2. | | 1535 | + SSLEngine engine = ctx.newEngine(UnpooledByteBufAllocator.DEFAULT); | | 1536 | + assertEquals(2, ReferenceCountUtil.refCnt(ctx)); | | 1537 | + | | 1538 | + // Drop the engine without releasing it, simulating a leak (e.g. handlerRemoved0 never firing). | | 1539 | + engine = null; | | 1540 | + | | 1541 | + // Collection triggers OpenSslEngine.finalize(), which releases the context (2 -> 1). | | 1542 | + while (ReferenceCountUtil.refCnt(ctx) != 1) { | | 1543 | + System.gc(); | | 1544 | + System.runFinalization(); | | 1545 | + Thread.sleep(50); | | 1546 | + } | | 1547 | + assertEquals(1, ReferenceCountUtil.refCnt(ctx)); | | 1548 | + } finally { | | 1549 | + ReferenceCountUtil.release(ctx); | | 1550 | + } | | 1551 | + } | | 1552 | + | 1518 | 1553 | @Override | 1519 | 1554 | protected SslProvider sslClientProvider() { | 1520 | 1555 | return OPENSSL; | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/test/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngineTest.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,13 @@ protected SslProvider sslServerProvider() { | 39 | 39 | return SslProvider.OPENSSL_REFCNT; | 40 | 40 | } | 41 | 41 |
| | 42 | + // OPENSSL_REFCNT has no finalizer, so the superclass's OPENSSL-only reclaim test does not apply here. | | 43 | + // Overriding it without @Test disables it for this subclass. | | 44 | + @Override | | 45 | + public void leakedEngineIsReclaimedWhileContextAlive() { | | 46 | + // noop | | 47 | + } | | 48 | + | 42 | 49 | @MethodSource("newTestParams") | 43 | 50 | @ParameterizedTest | 44 | 51 | public void testNotLeakOnException(SSLEngineTestParam param) throws Exception { | |
|