From cafcf7acc1f878459b416cb2e88907e8c29f3b08 Mon Sep 17 00:00:00 2001 From: Siyang Tang <82279870+TangSiyang2001@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:06:30 +0800 Subject: [PATCH] [cherry-pick](SSL) Fix ssl connection close 2.1 (#38587) (#38677) ## Proposed changes Issue Number: close #38590 If SSL connection closed, a specified packet will sent to indicate the closing of connection. The SSL engine will be shut down and output an empty unwrapped result. Therefore, handle this case correctly to avoid buffer overflow by breaking the reading flow and do the cleanup stuff initiatively. --- .../src/main/java/org/apache/doris/mysql/MysqlChannel.java | 2 +- .../main/java/org/apache/doris/qe/MysqlConnectProcessor.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java index 392b058758..61216c0a45 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java @@ -314,7 +314,7 @@ public class MysqlChannel implements BytesChannel { // before read, set limit to make read only one packet result.limit(result.position() + packetLen); readLen = readAll(result, false); - if (isSslMode && remainingBuffer.position() == 0) { + if (isSslMode && remainingBuffer.position() == 0 && result.hasRemaining()) { byte[] header = result.array(); int packetId = header[3] & 0xFF; if (packetId != sequenceId) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java index de918a88fa..8b3ba580ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java @@ -343,6 +343,11 @@ public class MysqlConnectProcessor extends ConnectProcessor { LOG.warn("Null packet received from network. remote: {}", channel.getRemoteHostPortString()); throw new IOException("Error happened when receiving packet."); } + if (!packetBuf.hasRemaining()) { + LOG.info("No more data to be read. Close connection. remote={}", channel.getRemoteHostPortString()); + ctx.setKilled(); + return; + } } catch (AsynchronousCloseException e) { // when this happened, timeout checker close this channel // killed flag in ctx has been already set, just return