-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mqtt][HA] ConcurrentHashMap to avoid ConcurrentModificationException #8239
Conversation
…cationException Signed-off-by: Aitor Iturrioz <[email protected]>
Travis tests have failedHey @bodiroga, |
@@ -65,7 +65,7 @@ | |||
private final Logger logger = LoggerFactory.getLogger(HomeAssistantDiscovery.class); | |||
protected final Map<String, Set<HaID>> componentsPerThingID = new TreeMap<>(); | |||
protected final Map<String, ThingUID> thingIDPerTopic = new TreeMap<>(); | |||
protected final Map<String, DiscoveryResult> results = new TreeMap<>(); | |||
protected final ConcurrentHashMap<String, DiscoveryResult> results = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the Map
in the declaration. But another suggestion:
Why don‘t you create an inner class
public static class HADiscoveryResult {
public final Set<HaId> components = new HashSet<>();
public @Nullable DiscoveryResult discoveryResult;
}
and use one Map<ThingUID, HADiscoveryResult>
instead of the two sets you have now? Makes it easier to be thread safe late when clearing the Map
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @J-N-K!
I have changed the results
declaration type, but I would prefer not to change the rest of the implementation, as it works fine. Do you think it's necessary?
Travis tests have failedHey @bodiroga, |
Signed-off-by: Aitor Iturrioz <[email protected]>
Hi @J-N-K! Sorry to bother you, but is there any option to get this merged for OH 2.5.8? And also: should I pay attention to Travis? Thank you! |
Travis fails in disabled itest |
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]> Signed-off-by: Clayton Tabone <[email protected]>
I do not think, that this will fix #7661
When we are at it, we should make The changes to results should not be needed, as all access is synchonized. |
Hi @jochen314! As you guys know more than me, I don't know if your proposed changes are really required or not, all I can say is that with the PR merged, I haven't seeing the error again. Was I the only one with that error message? |
I see. I did not notice, that you had my second change (line 168) already in. |
So it is just a matter of changing |
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]> Signed-off-by: Daan Meijer <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
…openhab#8239) * [mqtt][homeassistant] Use ConcurrentHashMap to avoid ConcurrentModificationException Signed-off-by: Aitor Iturrioz <[email protected]>
Hi @jochen314!
I've been able to fix the ConcurrentModifiedException errors using a ConcurrentHashMap for the 'results' of the discovery process.
What do you think?
Sadly the problem described in #7716 (comment) is still present 😞
Fixes #7661
Signed-off-by: Aitor Iturrioz [email protected]