SmartAxiom / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

Synchronization problem in ItemProvider #206

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
During my tests of the homematic binding, I am getting a lot of the following 
exceptions during startup and a few during running openhab:
17:57:58.928 ERROR OSGi[:98]- Exception while dispatching event 
org.osgi.service.event.Event [topic=openhab/update/LivingRoom_RC_Two_Right] to 
handler org.openhab.core.internal.items.ItemUpdater@518aeeca
java.util.ConcurrentModificationException: null
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
    at java.util.ArrayList$Itr.next(ArrayList.java:791)
    at org.openhab.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:91)
    at org.openhab.core.internal.items.ItemUpdater.receiveUpdate(ItemUpdater.java:71)
    at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:58)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Looking at the code of the ItemRegistryImpl, I see that the itemMap is indeed a 
synchronized Map. I actually don't know if it is intended that there are 
concurrent modifications of this list. It seems that they happen because of 
bindings being setup while others already operate and use the registry (only 
assumption).
If concurrent modification can occure then we should put all access to the 
itemMap into synchronized blocks (see JavaDoc Collections.synchronizedMap). 
When we do this we should also check that we do not introduce a deadlock :-(

This is not a blocker since it doesn't seem to be a permanent problem, after 
setup phase these errors disappear mostly.

Original issue reported on code.google.com by thomas.letsch.de on 11 Mar 2013 at 3:19

GoogleCodeExporter commented 8 years ago
Thanks for this bug report. Would you like to suggest a patch or shall I look 
into it?

Original comment by kai.openhab on 11 Mar 2013 at 4:57

GoogleCodeExporter commented 8 years ago
I have created a patch. It works on my machine, but these sync things are quite 
dangerous.

Original comment by thomas.letsch.de on 11 Mar 2013 at 9:31

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the patch - it looks good to me and I do not really expect deadlocks 
happening by this. Let's touch wood ;-)
I have pushed the patch here: 
https://code.google.com/p/openhab/source/detail?r=a93528cc4a23e9e7b329087f8b5283
c944ff6d51

Original comment by kai.openhab on 14 Mar 2013 at 8:25