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

Memory leak in SiriValueTransformer #165

Open
taasjord opened this issue Nov 22, 2024 · 0 comments
Open

Memory leak in SiriValueTransformer #165

taasjord opened this issue Nov 22, 2024 · 0 comments

Comments

@taasjord
Copy link

We think we found a memory leak in Anshar, as we saw heap usage kept growing over time. With profiling we identified SiriValueTransformer.cachedGettersForAdapter map to contain abnormal number of entries (millions of entries and several GB of data). The key in the map is of type GetterKey and this calculates its hashCode() from its two member variables, ValueAdapter.hashCode() and Class.hashCode().

The problem seems to be: ValueAdapter subclasses, including OutboundIdAdapter which is the most used, does not implement hashCode() so it uses the default Object.hashCode(), which usually is unique per object instance. Secondly, every call to MappingAdapterPresets.getOutboundAdapters creates new instances of several ValueAdapters, usually with same values, and this is sometimes called inline in Camel routes. Result of that is that cachedGettersForAdapter map will insert GetterKey on identical adapter instances but with different hash codes, so the map will continously grow and no entries are ever evicted.

The apparent fix could be to implement hashCode() in all ValueAdapter subclasses. But in addition it seems unnecessary to create new instances of these adapters all the time, so MappingAdapterPresets.getOutboundAdapters could either return a kind of singleton list per variation or make sure it is called outside the scope of the message flow and storing it, so that the same instances are always reused.

On a side request, are these adapters always required to run by internal processing, or could there be a way to disable them altogether or at least have configurable which ones to include?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant