Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public int read() throws IOException {

BytesReference message;

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

try {
BytesReference messageWithoutHeader = message.slice(6, message.length() - 6);
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());

// A message length of 6 bytes it is just a ping. Ignore for now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, should we check if the header is correct and if not close the connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens in the TcpFrameDecoder here. If the header is invalid, an exception is thrown .

When the exception is caught, the channel goes through out normal exception handling (and disconnect) logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good! just leave a comment about this in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment next to the usage of frame decoder to indicate that it would thrown an exception if the message turned out to be invalid.

if (messageLengthWithHeader != 6) {
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());
}
} catch (Exception e) {
handler.handleException(channel, e);
}
Expand Down