diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java index 18401cc2e8..7c6c1a4269 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java @@ -138,8 +138,12 @@ public class MysqlProto { serializer.reset(); MysqlHandshakePacket handshakePacket = new MysqlHandshakePacket(context.getConnectionId()); handshakePacket.writeTo(serializer); - channel.sendAndFlush(serializer.toByteBuffer()); - + try { + channel.sendAndFlush(serializer.toByteBuffer()); + } catch (IOException e) { + LOG.warn("Send and flush channel exception, ignore. Exception: " + e.toString()); + return false; + } // Server receive authenticate packet from client. ByteBuffer handshakeResponse = channel.fetchOnePacket(); if (handshakeResponse == null) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java index 04af03dd89..799a00529a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java @@ -54,18 +54,22 @@ public class NMysqlChannel extends MysqlChannel { * * @param dstBuf * @return - * @throws IOException */ @Override - protected int readAll(ByteBuffer dstBuf) throws IOException { + protected int readAll(ByteBuffer dstBuf) { int readLen = 0; - while (dstBuf.remaining() != 0) { - int ret = Channels.readBlocking(conn.getSourceChannel(), dstBuf); - // return -1 when remote peer close the channel - if (ret == -1) { - return readLen; + try { + while (dstBuf.remaining() != 0) { + int ret = Channels.readBlocking(conn.getSourceChannel(), dstBuf); + // return -1 when remote peer close the channel + if (ret == -1) { + return readLen; + } + readLen += ret; } - readLen += ret; + } catch (IOException e) { + LOG.warn("Read channel exception, ignore. Exception: " + e.toString()); + return 0; } return readLen; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java b/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java index 4343dbbbf9..ebd1f966a9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java @@ -183,14 +183,14 @@ public class MysqlProtoTest { Assert.assertTrue(MysqlProto.negotiate(context)); } - @Test(expected = IOException.class) + @Test public void testNegotiateSendFail() throws Exception { mockChannel("user", false); mockPassword(true); mockAccess(); ConnectContext context = new ConnectContext(null); MysqlProto.negotiate(context); - Assert.fail("No Exception throws."); + Assert.assertFalse(MysqlProto.negotiate(context)); } @Test