Skip to content
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] fix thread concurrency issue with type provider #14229

Merged
merged 1 commit into from
Jan 21, 2023

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Jan 15, 2023

I was getting the following errors in my log every time I tried to open a thing in MainUI shortly after booting:

2023-01-10 18:47:37.961 [ERROR] [internal.JSONResponseExceptionMapper] - Unexpected exception occurred while processing REST request.
java.lang.ArrayIndexOutOfBoundsException: Index 4052 out of bounds for length 4052
        at java.util.HashMap.valuesToArray(HashMap.java:973) ~[?:?]
        at java.util.HashMap$Values.toArray(HashMap.java:1050) ~[?:?]
        at java.util.ArrayList.addAll(ArrayList.java:670) ~[?:?]
        at org.openhab.core.thing.type.ChannelTypeRegistry.getChannelTypes(ChannelTypeRegistry.java:57) ~[?:?]

I was able to track it down to the MqttChannelTypeProvider. I presume that some component is just spamming a discover topic with the same config over and over, so the types field keeps getting updated from another thread while we're trying to copy the array over, and I happen to have a lot of channel types coming from MQTT. Switching to a thread safe data structure resolved the issue for me.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
@ccutrer ccutrer requested a review from davidgraeff as a code owner January 15, 2023 22:31
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo lolodomo merged commit e0adc8d into openhab:main Jan 21, 2023
@lolodomo lolodomo added the bug An unexpected problem or unintended behavior of an add-on label Jan 21, 2023
@lolodomo lolodomo added this to the 4.0 milestone Jan 21, 2023
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Feb 28, 2023
renescherer pushed a commit to renescherer/openhab-addons that referenced this pull request Mar 23, 2023
FordPrfkt pushed a commit to FordPrfkt/openhab-addons that referenced this pull request Apr 20, 2023
@ccutrer ccutrer deleted the mqtt-type-provider-concurrency branch November 29, 2023 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants