Xiaomi SPPv2: Catch exception thrown in onPacketReceived

When a received packet causes an exception to be thrown while
getting handled in the service's onPacketReceived method, the
message will get stuck in the queue because it is never released.
Subsequently received messages get lined up after the first message
that causes an exception, and since that message is never removed,
those newer messages are never processed.

Catching the exception thrown from within the onPacketReceived method
allows the code flow to continue and therefore remove the troubling
message from the queue.
This commit is contained in:
MrYoranimo 2024-11-18 23:17:44 +01:00
parent 1d2404a4e6
commit b5bd4da9b1

View File

@ -105,7 +105,11 @@ public class XiaomiSppProtocolV2 extends AbstractXiaomiSppProtocol {
break;
case PACKET_TYPE_DATA:
XiaomiSppPacketV2.DataPacket dataPacket = (XiaomiSppPacketV2.DataPacket) decodedPacket;
support.onPacketReceived(dataPacket.getChannel(), dataPacket.getPayloadBytes(support.getAuthService()));
try {
support.onPacketReceived(dataPacket.getChannel(), dataPacket.getPayloadBytes(support.getAuthService()));
} catch (final Exception ex) {
LOG.error("Exception while handling received packet", ex);
}
// TODO: only directly ack protobuf packets, bulk ack others
sendAck(decodedPacket.getSequenceNumber());
break;