Skip to content

Commit f6055dc

Browse files
committed
Suppress noisy SSL exceptions (#61359)
If a TLS-protected connection closes unexpectedly then today we often emit a `WARN` log, typically one of the following: io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Insufficient buffer remaining for AEAD cipher fragment (2). Needs to be more than tag size (16) io.netty.handler.codec.DecoderException: javax.net.ssl.SSLException: Received close_notify during handshake We typically only report unexpectedly-closed connections at `DEBUG` level, but these two messages don't follow that rule and generate a lot of noise as a result. This commit adjusts the logging to report these two exceptions at `DEBUG` level only.
1 parent b866aaf commit f6055dc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SSLExceptionHelper.java

+13
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
import io.netty.handler.codec.DecoderException;
1010
import io.netty.handler.ssl.NotSslRecordException;
11+
import org.elasticsearch.common.regex.Regex;
1112

1213
import javax.net.ssl.SSLException;
14+
import javax.net.ssl.SSLHandshakeException;
1315

1416
public class SSLExceptionHelper {
1517

@@ -22,6 +24,11 @@ public static boolean isNotSslRecordException(Throwable e) {
2224
}
2325

2426
public static boolean isCloseDuringHandshakeException(Throwable e) {
27+
return isCloseDuringHandshakeSSLException(e)
28+
|| isCloseDuringHandshakeSSLException(e.getCause());
29+
}
30+
31+
private static boolean isCloseDuringHandshakeSSLException(Throwable e) {
2532
return e instanceof SSLException
2633
&& e.getCause() == null
2734
&& "Received close_notify during handshake".equals(e.getMessage());
@@ -32,4 +39,10 @@ public static boolean isReceivedCertificateUnknownException(Throwable e) {
3239
&& e.getCause() instanceof SSLException
3340
&& "Received fatal alert: certificate_unknown".equals(e.getCause().getMessage());
3441
}
42+
43+
public static boolean isInsufficientBufferRemainingException(Throwable e) {
44+
return e instanceof DecoderException
45+
&& e.getCause() instanceof SSLHandshakeException
46+
&& Regex.simpleMatch("Insufficient buffer remaining for AEAD cipher fragment*", e.getCause().getMessage());
47+
}
3548
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SecurityTransportExceptionHandler.java

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public void accept(TcpChannel channel, Exception e) {
3434
} else if (SSLExceptionHelper.isCloseDuringHandshakeException(e)) {
3535
logger.debug("connection {} closed during handshake", channel);
3636
CloseableChannel.closeChannel(channel);
37+
} else if (SSLExceptionHelper.isInsufficientBufferRemainingException(e)) {
38+
logger.debug("connection {} closed abruptly", channel);
39+
CloseableChannel.closeChannel(channel);
3740
} else if (SSLExceptionHelper.isReceivedCertificateUnknownException(e)) {
3841
logger.warn("client did not trust this server's certificate, closing connection {}", channel);
3942
CloseableChannel.closeChannel(channel);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/SecurityHttpExceptionHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.function.BiConsumer;
1414

1515
import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isCloseDuringHandshakeException;
16+
import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isInsufficientBufferRemainingException;
1617
import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isNotSslRecordException;
1718
import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isReceivedCertificateUnknownException;
1819

@@ -39,6 +40,9 @@ public void accept(HttpChannel channel, Exception e) {
3940
} else if (isCloseDuringHandshakeException(e)) {
4041
logger.debug("connection {} closed during ssl handshake", channel);
4142
CloseableChannel.closeChannel(channel);
43+
} else if (isInsufficientBufferRemainingException(e)) {
44+
logger.debug("connection {} closed abruptly", channel);
45+
CloseableChannel.closeChannel(channel);
4246
} else if (isReceivedCertificateUnknownException(e)) {
4347
logger.warn("http client did not trust this server's certificate, closing connection {}", channel);
4448
CloseableChannel.closeChannel(channel);

0 commit comments

Comments
 (0)