Skip to content

Commit 6c58f0c

Browse files
authored
Handle ping correctly in NioTransport (#25462)
Our current TCPTransport logic assumes that we do not pass pings to the TCPTransport level. This commit fixes an issue where NioTransport was passing pings to TCPTransport and leading to exceptions.
1 parent acade2b commit 6c58f0c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/framework/src/main/java/org/elasticsearch/transport/nio/channel/TcpReadContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public int read() throws IOException {
6767

6868
BytesReference message;
6969

70+
// Frame decoder will throw an exception if the message is improperly formatted, the header is incorrect,
71+
// or the message is corrupted
7072
while ((message = frameDecoder.decode(createCompositeBuffer(), rawBytesCount)) != null) {
7173
int messageLengthWithHeader = message.length();
7274
NetworkBytesReference.vectorizedIncrementReadIndexes(references, messageLengthWithHeader);
@@ -75,7 +77,11 @@ public int read() throws IOException {
7577

7678
try {
7779
BytesReference messageWithoutHeader = message.slice(6, message.length() - 6);
78-
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());
80+
81+
// A message length of 6 bytes it is just a ping. Ignore for now.
82+
if (messageLengthWithHeader != 6) {
83+
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());
84+
}
7985
} catch (Exception e) {
8086
handler.handleException(channel, e);
8187
}

0 commit comments

Comments
 (0)