Subject: | Found a bug in 1.24: missing messages and stucked receiving |
Date: | Wed, 19 Aug 2020 10:43:32 +0200 |
To: | bug-Net-MQTT-Simple [...] rt.cpan.org |
From: | Peter Sobisch <petersob [...] gmx.net> |
Hello Juerd,
I've tested Net::MQTT::Simple with mosquitto 1.5.7 (tcp 1883 via localhost) by sending 1000 message with ca 50 bytes at once and experienced missing messages and receiving stucked for a while until timeout and reconnect occurred. Sometimes after 208 and sometimes after 850 messages.
I digged in into Simple.pm and added some additional printfs and found out, that the cause was losing sync due to creating a to short packet:
my $packet = {
type => ($first_byte & 0xF0) >> 4,
dup => ($first_byte & 0x08) >> 3,
qos => ($first_byte & 0x06) >> 1,
retain => ($first_byte & 0x01),
data => substr($$bufref, $offset, $length),
};
the exactly proble was: the $length was different from real lengtt of $packet->{data}.
I went back a couple of lines and found a comparison which turn out to be the actually problem:
return if $length > (length $$bufref) + $offset; # not enough data yet
so I suppose it should be:
return if $length > (length $$bufref) - $offset; # not enough data yet
after changing that i've got rid this problem.
with best Regards,
Peter