Skip to content

fix: Avoid clearing updated keys on twin update#3570

Merged
albinsuresh merged 1 commit intothin-edge:mainfrom
albinsuresh:fix/3559/direct-twin-value-replace
Apr 21, 2025
Merged

fix: Avoid clearing updated keys on twin update#3570
albinsuresh merged 1 commit intothin-edge:mainfrom
albinsuresh:fix/3559/direct-twin-value-replace

Conversation

@albinsuresh
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh commented Apr 18, 2025

Bug RCA

The test flakiness where the twin/name fragment was becoming null after the same was updated with a new value because of a faulty logic in how twin updates are handled. When a given twin fragment is updated with a new value, instead of overwriting the existing value with the new one, the current code was trying to clear the old value with a null message first, followed by publishing the updated value. This is the cause of the race, as sometimes, the twin query in the test was happening immediately after the null value is processed which results in empty response.

Proposed changes

When existing twin data like {"a": 1, "b": 2, "c": 3} is updated with {"b": 2, "c": 4, "d": 5}, the update is handled as follows:

  1. The removed key: "a" is cleared
  2. The unchanged key: "b" is not republished
  3. The updated key: "c" is republished with the new value 4
  4. The new key: "d" is published as new

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

#3559

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

When existing twin data like {"a": 1, "b": 2, "c": 3} is updated with {"b": 2, "c": 4, "d": 5}
the update is handled as follows:
1. The removed key: "a" is cleared
2. The unchanged key: "b" is not republished
3. The updated key: "c" is republished with the new value 4
4. The new key: "d" is published as new
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ates/core/tedge_agent/src/entity_manager/server.rs 55.55% 3 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.

@github-actions
Copy link
Copy Markdown
Contributor

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
615 0 3 615 100 1h48m25.240506s

@albinsuresh albinsuresh marked this pull request as ready for review April 18, 2025 15:35
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.

@albinsuresh albinsuresh added this pull request to the merge queue Apr 21, 2025
Merged via the queue into thin-edge:main with commit 8b93df6 Apr 21, 2025
34 checks passed
@albinsuresh albinsuresh deleted the fix/3559/direct-twin-value-replace branch April 25, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants