From fee73749a3a6fbbc930bf335ae92aaec10f697b4 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Tue, 30 Jul 2024 20:54:34 +0200 Subject: [PATCH] fix handling of messages with packet id 0 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 --- crates/extensions/tedge_mqtt_bridge/src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/extensions/tedge_mqtt_bridge/src/lib.rs b/crates/extensions/tedge_mqtt_bridge/src/lib.rs index 20e5e81381e..a19fd854845 100644 --- a/crates/extensions/tedge_mqtt_bridge/src/lib.rs +++ b/crates/extensions/tedge_mqtt_bridge/src/lib.rs @@ -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))) => {