Close SSLEngine when connection fails.
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: https://github.com/grpc/grpc-java/issues/3080
This commit is contained in:
parent
bf8cac4939
commit
c11b23bbc1
@ -1527,6 +1527,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
try {
|
try {
|
||||||
// Release all resources such as internal buffers that SSLEngine
|
// Release all resources such as internal buffers that SSLEngine
|
||||||
// is managing.
|
// is managing.
|
||||||
|
outboundClosed = true;
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
|
|
||||||
if (closeInbound) {
|
if (closeInbound) {
|
||||||
@ -1574,6 +1575,9 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
|
|
||||||
private void closeOutboundAndChannel(
|
private void closeOutboundAndChannel(
|
||||||
final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception {
|
final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception {
|
||||||
|
outboundClosed = true;
|
||||||
|
engine.closeOutbound();
|
||||||
|
|
||||||
if (!ctx.channel().isActive()) {
|
if (!ctx.channel().isActive()) {
|
||||||
if (disconnect) {
|
if (disconnect) {
|
||||||
ctx.disconnect(promise);
|
ctx.disconnect(promise);
|
||||||
@ -1583,9 +1587,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outboundClosed = true;
|
|
||||||
engine.closeOutbound();
|
|
||||||
|
|
||||||
ChannelPromise closeNotifyPromise = ctx.newPromise();
|
ChannelPromise closeNotifyPromise = ctx.newPromise();
|
||||||
try {
|
try {
|
||||||
flush(ctx, closeNotifyPromise);
|
flush(ctx, closeNotifyPromise);
|
||||||
|
Loading…
Reference in New Issue
Block a user