Skip to content

Commit

Permalink
fix handling of messages with packet id 0
Browse files Browse the repository at this point in the history
Messages with packet id 0 should be handled
differently as they won't receive a PubAck or
PubRec control messages hence it will never
be removed from the hashmap and future
messages with packet id 0 are ignored

Signed-off-by: Reuben Miller <[email protected]>
  • Loading branch information
reubenmiller committed Jul 31, 2024
1 parent e790772 commit fcaafac
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/extensions/tedge_mqtt_bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,23 @@ async fn half_bridge(

// Keep track of packet IDs so we can acknowledge messages
Event::Outgoing(Outgoing::Publish(pkid)) => {
if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid) {
if pkid == 0 {
// Messages with pkid 0 (meaning QoS=0) should not be added to the hashmap
// as multiple messages with the pkid=0 can be received
match companion_bridge_half.recv().await {
// A message was forwarded by the other bridge half, note the packet id
Some(Some((topic, msg))) => {
loop_breaker.forward_on_topic(topic, &msg);
}

// A healthcheck message was published, ignore this packet id
Some(None) => {}

// The other bridge half has disconnected, break the loop and shut down the bridge
None => break,
}
} else if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid)
{
match companion_bridge_half.recv().await {
// A message was forwarded by the other bridge half, note the packet id
Some(Some((topic, msg))) => {
Expand Down

0 comments on commit fcaafac

Please sign in to comment.