Skip to content

Commit 3c9cfc0

Browse files
authored
Merge pull request #3697 from albinsuresh/imp/no-dynamic-connection-on-deregster-no-op
fix: no dynamic connection when deregister does nothing
2 parents bff20b2 + e585642 commit 3c9cfc0

File tree

1 file changed

+8
-2
lines changed
  • crates/core/tedge_agent/src/entity_manager

1 file changed

+8
-2
lines changed

crates/core/tedge_agent/src/entity_manager/server.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ impl EntityStoreServer {
317317

318318
async fn deregister_entity(&mut self, topic_id: &EntityTopicId) -> Vec<EntityMetadata> {
319319
let deleted = self.entity_store.deregister_entity(topic_id);
320+
if deleted.is_empty() {
321+
return deleted;
322+
}
320323

321324
let mut topics = TopicFilter::empty();
322325
for entity in deleted.iter() {
@@ -338,12 +341,15 @@ impl EntityStoreServer {
338341
}
339342

340343
// A single connection to retrieve all retained metadata messages for all deleted entities
341-
match self.mqtt_connector.connect(topics).await {
344+
match self.mqtt_connector.connect(topics.clone()).await {
342345
Ok(mut connection) => {
343346
while let Ok(Some(message)) =
344347
timeout(Duration::from_secs(1), connection.next_message()).await
345348
{
346-
if message.retain && !message.payload_bytes().is_empty() {
349+
if message.retain
350+
&& !message.payload_bytes().is_empty()
351+
&& topics.accept(&message)
352+
{
347353
let clear_msg = MqttMessage::new(&message.topic, "").with_retain();
348354
if let Err(err) = self.mqtt_publisher.send(clear_msg).await {
349355
error!(

0 commit comments

Comments
 (0)