ARTEMIS-6199 Fix race in WildcardAddressManager - #6637
Merged
Conversation
Contributor
Author
|
FYI - The full test-suite is green on this. |
When a message is routed, the Bindings for the address is fetched from the address manager. If the Bindings doesn't already exist then it is created. Creating the bindings involves traversing the address tree map to find all matching wildcard addresses. When a matching address is found its bindings are copied. Traversing the address tree map is performed without any kind of synchronization. Therefore, a concurrent operation to remove a binding can modify a wildcard address's Bindings mid-copy. This produces a Bindings that is missing the binding being concurrently removed. The removeBinding visitor then walks matching addresses to remove the binding from each, but fails with IllegalStateException on the address where the binding was never copied. This can also leak entires in addressMap & mappings eventually leading to OOME, since the exception aborts the visitor traversal and skips cleanup of remaining addresses. - Add addressMapLock to synchronize the lazy-creation path in getBindingsForRoutingAddress with addBinding, removeBinding, removeAddressInfo, and clear. The common path (cache hit) does not acquire the lock. - Catch IllegalStateException in the removeBinding visitor as defense-in-depth so that a missing binding does not abort the traversal and leak remaining entries. - Add tests to reproduce the race: a deterministic test that simulates the inconsistent state and verifies the visitor handles the missing binding, and a concurrent stress test that exercises getBindingsForRoutingAddress against wildcard binding add/remove. Co-Authored-By: Claude <noreply@anthropic.com>
clebertsuconic
approved these changes
Aug 24, 2026
Contributor
|
looked though it and LGTM |
Contributor
|
(I am assuming the tests reproduced the issue and no regressions happened on the whole testsuite) if those are good.. I aprove the changes. |
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.
When a message is routed, the Bindings for the address is fetched from the address manager. If the Bindings doesn't already exist then it is created. Creating the bindings involves traversing the address tree map to find all matching wildcard addresses. When a matching address is found its bindings are copied.
Traversing the address tree map is performed without any kind of synchronization. Therefore, a concurrent operation to remove a binding can modify a wildcard address's Bindings mid-copy. This produces a Bindings that is missing the binding being concurrently removed. The removeBinding visitor then walks matching addresses to remove the binding from each, but fails with IllegalStateException on the address where the binding was never copied. This can also leak entires in addressMap & mappings eventually leading to OOME, since the exception aborts the visitor traversal and skips cleanup of remaining addresses.