Skip to content

Commit

Permalink
Close SSLEngine when connection fails.
Browse files Browse the repository at this point in the history
Motivation:
When using the JdkSslEngine, the ALPN class is used keep a reference
to the engine.   In the event that the TCP connection fails, the
SSLEngine is not removed from the map, creating a memory leak.

Modification:
Always close the SSLEngine regardless of if the channel became
active.  Also, record the SSLEngine was closed in all places.

Result:
Fixes: grpc/grpc-java#3080
  • Loading branch information
carl-mastrangelo committed Feb 22, 2018
1 parent 268b901 commit ec060d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions handler/src/main/java/io/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ private void setHandshakeFailure(ChannelHandlerContext ctx, Throwable cause, boo
try {
// Release all resources such as internal buffers that SSLEngine
// is managing.
outboundClosed = true;
engine.closeOutbound();

if (closeInbound) {
Expand Down Expand Up @@ -1557,6 +1558,9 @@ private void notifyClosePromise(Throwable cause) {

private void closeOutboundAndChannel(
final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception {
outboundClosed = true;
engine.closeOutbound();

if (!ctx.channel().isActive()) {
if (disconnect) {
ctx.disconnect(promise);
Expand All @@ -1566,9 +1570,6 @@ private void closeOutboundAndChannel(
return;
}

outboundClosed = true;
engine.closeOutbound();

ChannelPromise closeNotifyPromise = ctx.newPromise();
try {
flush(ctx, closeNotifyPromise);
Expand Down

0 comments on commit ec060d1

Please sign in to comment.