Skip to content

Commit a7ea7cf

Browse files
johnouslandelle
authored andcommitted
Support for OpenSslEngine with no finalizer (#1669)
Motivation: Support for Netty SslProvider.OPENSSL_REFCNT (OpenSSL-based implementation which does not have finalizers and instead implements ReferenceCounted). Modification: Add destroy method to SslEngineFactory to allow cleaning up reference counted SslContext. Result: Users can opt-in to a finalizer free OpenSslEngine and OpenSslContext.
1 parent 7fd935e commit a7ea7cf

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Diff for: client/src/main/java/org/asynchttpclient/SslEngineFactory.java

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public interface SslEngineFactory {
3939
default void init(AsyncHttpClientConfig config) throws SSLException {
4040
// no op
4141
}
42+
43+
/**
44+
* Perform any necessary cleanup.
45+
*/
46+
default void destroy() {
47+
// no op
48+
}
49+
4250
}

Diff for: client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.netty.channel.*;
1919
import io.netty.channel.epoll.EpollEventLoopGroup;
2020
import io.netty.channel.group.ChannelGroup;
21+
import io.netty.channel.group.ChannelGroupFuture;
2122
import io.netty.channel.group.DefaultChannelGroup;
2223
import io.netty.channel.kqueue.KQueueEventLoopGroup;
2324
import io.netty.channel.nio.NioEventLoopGroup;
@@ -287,8 +288,9 @@ public void removeAll(Channel connection) {
287288
}
288289

289290
private void doClose() {
290-
openChannels.close();
291+
ChannelGroupFuture groupFuture = openChannels.close();
291292
channelPool.destroy();
293+
groupFuture.addListener(future -> sslEngineFactory.destroy());
292294
}
293295

294296
public void close() {

Diff for: client/src/main/java/org/asynchttpclient/netty/ssl/DefaultSslEngineFactory.java

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.handler.ssl.SslContextBuilder;
2020
import io.netty.handler.ssl.SslProvider;
2121
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
22+
import io.netty.util.ReferenceCountUtil;
2223
import org.asynchttpclient.AsyncHttpClientConfig;
2324

2425
import javax.net.ssl.SSLEngine;
@@ -73,6 +74,11 @@ public void init(AsyncHttpClientConfig config) throws SSLException {
7374
sslContext = buildSslContext(config);
7475
}
7576

77+
@Override
78+
public void destroy() {
79+
ReferenceCountUtil.release(sslContext);
80+
}
81+
7682
/**
7783
* The last step of configuring the SslContextBuilder used to create an SslContext when no context is provided in the {@link AsyncHttpClientConfig}. This defaults to no-op and
7884
* is intended to be overridden as needed.

0 commit comments

Comments
 (0)