Skip to content

[YAML thing provider] Clean retry queue when a thing is updated/removed#5361

Draft
lolodomo wants to merge 1 commit intoopenhab:mainfrom
lolodomo:yaml_thing_clean_queue
Draft

[YAML thing provider] Clean retry queue when a thing is updated/removed#5361
lolodomo wants to merge 1 commit intoopenhab:mainfrom
lolodomo:yaml_thing_clean_queue

Conversation

@lolodomo
Copy link
Contributor

No description provided.

@lolodomo lolodomo requested a review from a team as a code owner February 15, 2026 09:51
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo lolodomo force-pushed the yaml_thing_clean_queue branch from 9983375 to 75b0aa3 Compare February 15, 2026 11:04
@lolodomo lolodomo changed the title [YAML thing] Clean retry queue when a thing is updated/removed [YAML thing provider] Clean retry queue when a thing is updated/removed Feb 15, 2026
@lolodomo lolodomo marked this pull request as draft February 15, 2026 12:02
@lolodomo
Copy link
Contributor Author

Put the PR in draft mode to do more tests.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enhances the YamlThingProvider to properly manage the retry queue when things are updated or removed from YAML configuration models. The changes prevent stale entries from accumulating in the retry queue by cleaning them up when things are updated or removed, and adds synchronization to ensure thread-safe access to the queue.

Changes:

  • Added synchronization (queueLock) to all retry queue operations to prevent race conditions
  • Implemented removeFromRetryQueue method to clean up entries when things are updated or removed
  • Integrated queue cleanup into updatedModel and removedModel methods for non-isolated models

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +571 to +575
for (QueueContent qc : queue) {
if (thingUID.equals(qc.thingUID)) {
queue.remove(qc);
}
}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The new removeFromRetryQueue method and its integration with updatedModel/removedModel lack test coverage. Consider adding tests to verify: 1) items are correctly removed from the retry queue when a thing is updated/removed, 2) the method handles concurrent access correctly, 3) the cleanup happens only for non-isolated models. This is especially important given the concurrency aspects of this code.

Suggested change
for (QueueContent qc : queue) {
if (thingUID.equals(qc.thingUID)) {
queue.remove(qc);
}
}
queue.removeIf(qc -> thingUID.equals(qc.thingUID));

Copilot uses AI. Check for mistakes.
Comment on lines +571 to +575
for (QueueContent qc : queue) {
if (thingUID.equals(qc.thingUID)) {
queue.remove(qc);
}
}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The removeFromRetryQueue method continues iterating through all queue elements even after finding and removing a match. This is inefficient and could also remove multiple entries if duplicate thingUID entries exist in the queue. Consider adding a break statement after queue.remove(qc) to exit the loop once a match is found, or use queue.removeIf(qc -> thingUID.equals(qc.thingUID)) which is more efficient and idiomatic.

Suggested change
for (QueueContent qc : queue) {
if (thingUID.equals(qc.thingUID)) {
queue.remove(qc);
}
}
queue.removeIf(qc -> thingUID.equals(qc.thingUID));

Copilot uses AI. Check for mistakes.
@Override
public void run() {
logger.debug("Starting lazy retry thread");
while (!queue.isEmpty()) {
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The queue.isEmpty() check at line 112 is performed outside the synchronized block, which could lead to a race condition. If the queue becomes empty between the check and entering the synchronized block, or if items are added/removed by other threads, the loop might not behave as expected. Consider moving the isEmpty() check inside the synchronized block or restructuring the loop to check emptiness within the synchronized section.

Copilot uses AI. Check for mistakes.
}
}
}
if (!queue.isEmpty()) {
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

Similar to line 112, this queue.isEmpty() check is performed outside the synchronized block, which could lead to a race condition. The queue state might change between this check and the next iteration of the while loop at line 112. Consider performing this check within a synchronized block for consistency with the rest of the queue operations.

Copilot uses AI. Check for mistakes.
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.

1 participant

Comments