A chat server was set up within the group using the MQTT protocol. The day before yesterday, during the test for large messages (exceeding 5000 Chinese characters), the connection became unusable, and no subsequent messages received any response.
Server environment: Netty: 4.1.32.Final Using the MqttDecoder built into the Netty package
Client: Android
Investigation Process
Since all the messages were logged, we first searched the server logs and found that there was no content of the sent messages in the logs.
Could it be that the client did not send the message when it was too long? We used tcpdump to capture the packets and found that the client was sending normally, and the server had already acknowledged all the packets, but the server did not send back any responses, leading us to suspect that the server failed to process large messages.
Using tcpdump with the -nn option to print IP addresses and ports, and -X to print the contents of the network packets, you can also use the -w option to save it to a file and then analyze it with tcpdump or wireshark
Then, we checked the maximum payload supported by MQTT. The official MQTT documentation states it is 256M, which the message size definitely does not exceed.
We captured another packet on the server and confirmed the message was received but no acknowledgment was sent back.
Upon enabling online debugging, we found a PUBLISH type message was received, but the message’s class was not MqttPublishMessage, and the payload was empty, yet there was an error message in the Message: too large message: 56234 bytes
Upon Googling, we found someone encountered the same issue, even though MQTT was using C language in this issue.
We inspected MqttDecoder and discovered that the decoder has a maximum payload limit (part of the code is below), and the launch code called the default constructor, so the maximum data by default is 8092 bytes.
JavaScript code excerpt:
public final class MqttDecoder extends ReplayingDecoder { private static final int DEFAULT_MAX_BYTES_IN_MESSAGE = 8092; public MqttDecoder() { this(DEFAULT_MAX_BYTES_IN_MESSAGE); } public MqttDecoder(int maxBytesInMessage) { super(DecoderState.READ_FIXED_HEADER); this.maxBytesInMessage = maxBytesInMessage; } @Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List