Skip to content

fix: clear all retained entity messages on entity deregistration#3681

Merged
albinsuresh merged 1 commit intothin-edge:mainfrom
albinsuresh:fix/3632/track-all-entity-retained-messages-v2
Jun 19, 2025
Merged

fix: clear all retained entity messages on entity deregistration#3681
albinsuresh merged 1 commit intothin-edge:mainfrom
albinsuresh:fix/3632/track-all-entity-retained-messages-v2

Conversation

@albinsuresh
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh commented Jun 12, 2025

Proposed changes

On entity deregistration, fetch all retained messages associated with that entity and its children and then clear them all.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#3632

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@albinsuresh albinsuresh temporarily deployed to Test Pull Request June 12, 2025 10:42 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 12, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
651 0 3 651 100 1h49m58.177953s

@albinsuresh albinsuresh temporarily deployed to Test Pull Request June 12, 2025 19:31 — with GitHub Actions Inactive
@albinsuresh albinsuresh force-pushed the fix/3632/track-all-entity-retained-messages-v2 branch from 81deebf to 8cd679f Compare June 12, 2025 20:31
@albinsuresh albinsuresh temporarily deployed to Test Pull Request June 12, 2025 20:31 — with GitHub Actions Inactive
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 82.67717% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/extensions/tedge_mqtt_ext/src/lib.rs 0.00% 17 Missing ⚠️
...ates/core/tedge_agent/src/entity_manager/server.rs 85.71% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@albinsuresh albinsuresh temporarily deployed to Test Pull Request June 12, 2025 21:33 — with GitHub Actions Inactive
@albinsuresh albinsuresh marked this pull request as ready for review June 12, 2025 22:01
Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider to fully remove the concept of MqttConnector API and to directly use regular mqtt_channel connections.

Comment on lines +316 to +317
// Clear all retained metadata/data associated with the entity
match self.mqtt_connector.connection_for(&entity.topic_id).await {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider to spawn the whole loop in a background task (including open & close of the connection).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that really help? Because, even if we spawn it as a different task, we'll still have to wait for that task to finish here, as we can't return from this deregister call before everything is cleared.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we can't return from this deregister call before everything is cleared.

Why not? This was my proposal. I see clearing all these retained messages as a follow-up task of entity de-registration. But, I agree that this can be discussed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see clearing all these retained messages as a follow-up task of entity de-registration. But, I agree that this can be discussed.

Since one of the main highlights of the HTTP API was the feedback after something is complete, returning while the operation is still in-progress in the background feels a bit weird. As a user, I personally prefer the deterministic behaviour, esp since this is a rare operation and hence I'm okay with waiting a bit more until everything is fully complete. But I'll let @reubenmiller also pitch in, if the proposed eventual cleanup is sufficient.

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. However, two failing unit-tests require investigation.

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Thank you for taking the time to find the correct approach.

@albinsuresh albinsuresh force-pushed the fix/3632/track-all-entity-retained-messages-v2 branch from 5cec94f to 405330d Compare June 19, 2025 05:48
@albinsuresh albinsuresh temporarily deployed to Test Pull Request June 19, 2025 05:48 — with GitHub Actions Inactive
@albinsuresh albinsuresh added this pull request to the merge queue Jun 19, 2025
Merged via the queue into thin-edge:main with commit ac991c0 Jun 19, 2025
34 checks passed
@albinsuresh albinsuresh deleted the fix/3632/track-all-entity-retained-messages-v2 branch June 19, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:entity_store Entity store related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants