Skip to content

Commit

Permalink
Support for OpenSslEngine with no finalizer (#1669)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnou authored and slandelle committed Oct 16, 2019
1 parent 7fd935e commit a7ea7cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public interface SslEngineFactory {
default void init(AsyncHttpClientConfig config) throws SSLException {
// no op
}

/**
* Perform any necessary cleanup.
*/
default void destroy() {
// no op
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.netty.channel.*;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.ChannelGroupFuture;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
Expand Down Expand Up @@ -287,8 +288,9 @@ public void removeAll(Channel connection) {
}

private void doClose() {
openChannels.close();
ChannelGroupFuture groupFuture = openChannels.close();
channelPool.destroy();
groupFuture.addListener(future -> sslEngineFactory.destroy());
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.util.ReferenceCountUtil;
import org.asynchttpclient.AsyncHttpClientConfig;

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

@Override
public void destroy() {
ReferenceCountUtil.release(sslContext);
}

/**
* 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
* is intended to be overridden as needed.
Expand Down

0 comments on commit a7ea7cf

Please sign in to comment.