Selectorparser fix - Possible memory leak - The size of LRUCache can grow above the maxCacheSize limit calling the put method concurrently #197
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.
I do not know whether this is the correct way of communicating an issue or not, so pardon me in advance.
We use Artemis ActiveMQ version 1.1.0-wildfly-017 in production and recently we have encountered OOM exception in one of our server log. We recorded a HPROF dump and we could trace back the issue to LRUCache which stored more than 900.000 entries even though that the maxCacheSize is set to 100.
The LRUCahce uses LinkedHashMap which is not thread-safe. So putting new entries concurrently in the map could render removeEldestEntry ineffective because it is called after put is called (and we had put calls very close to each other in time).
We were able to reproduce this issue and then we made this slight code change (wrapping the LRUCache into a synchronized map in SelectorParser.java). We tested the solution and we saw that the size of the map never grew above the maxCacheSize limit.
A sidenote:
I serched for issues similar to ours and came across this one: https://issues.apache.org/jira/browse/AMQ-2290 (I could not find anything else which resembled to our problem)
Therefore we implemented the exact same solution.