Repository navigation
Conversation
assetIdGatewayIdMap is written under synchronization in processGatewayChildAssetChange but read unsynchronized in onAttributeEventIntercepted, deleteGateway and getLocallyRegisteredGatewayId, which constitutes a data race (e.g. ConcurrentModificationException while streaming the entry set). Use a ConcurrentHashMap like the adjacent gatewayConnectorMap and tunnelInfos fields. Fixes openremote#3449 Co-Authored-By: Claude Code <noreply@anthropic.com>
Member
|
Hi @cgrs5722 thanks for picking this up, by switching to |
Member
|
@cgrs5722 would be great to get this finished off, otherwise we'll have to close this off. |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
GatewayService.assetIdGatewayIdMapis a plainHashMapthat is written undersynchronizedinprocessGatewayChildAssetChange, but read without any synchronization from:onAttributeEventIntercepted(get, attribute event interceptor thread)deleteGateway(entrySet().stream()while writes can happen concurrently)getLocallyRegisteredGatewayId(get, called from the Camel route predicate)This is a data race: unsynchronized reads against synchronized writes on a
HashMapcan throwConcurrentModificationExceptionwhile streaming the entry set, or observe inconsistent state.The fix switches the map to
ConcurrentHashMap, consistent with the adjacentgatewayConnectorMapandtunnelInfosfields.Fixes #3449.
Verification
./gradlew :manager:compileJavapasses (JDK 21).synchronizedput/remove as inprocessGatewayChildAssetChange, another thread doingget+entrySet().stream().filter(...)as indeleteGateway) fails withConcurrentModificationExceptiononHashMapwithin ~1000 reads, whileConcurrentHashMapcompletes hundreds of thousands of operations without error.testproject (e.g.GatewayTest) require a running PostgreSQL + Keycloak stack via docker compose, which I don't have available locally.🤖 Generated with Claude Code