heapless 0.9.3 Deque::make_contiguous() corrupts a wrapped queue whose tail
fits into the free space: it sets back to 0 instead of the end of the data, so
the queue gains a stray byte (8 queued bytes become 9). The receive queue
calls make_contiguous() before every parse, so the MQTT stream gets out of step
and the next packet fails with UnknownPacketType or MalformedVarInt. Whether it
happens depends on where the queue wraps, which made it look like a race on the
devices (a firmware upload interleaved with other messages). The transmit queue
uses make_contiguous() in pending_transmit() as well.
Fixed upstream, but not released yet (0.9.3 is the latest release):
https://github.com/rust-embedded/heapless/pull/695367accdec4
The full queue case worked around by keeping one byte free:
https://github.com/rust-embedded/heapless/issues/676
Both queues are now a LinearBuffer: a fixed size array whose contents always
start at index 0. Bytes are appended at the back and removed from the front a
packet or a block at a time with one copy_within, so the contents never wrap,
are always one slice and need no compaction. handle_sent() and the packet
drain remove bytes in bulk instead of one pop_front() per byte, a partly sent
block gets its length byte rewritten in place. handle_received_slice() stores
all of the bytes or none of them. The one free byte of the old workaround is
no longer kept.
heapless::format! for the numbers is replaced by a small decimal writer, and
the heapless dependency is dropped.