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

Fix memory leak on netty #3059

Merged
merged 4 commits into from
May 25, 2021
Merged

Conversation

laurit
Copy link
Contributor

@laurit laurit commented May 21, 2021

Resolves #3027
Instead of ContextStore use Cache with weak keys and weak values to store link between original listener and wrapper. ContextStore works fine when wrapper is stored in a field on original listener, but when listener class is a lambda instead of field it gets stored in a map with weak keys where original listener is key and wrapper is value. As wrapper has a strong reference to original this causes a memory leak.

@mateuszrzeszutek
Copy link
Member

Can you add a comment to the FutureListenerWrappers class why a cache is used instead of context store? (basically what you wrote in the PR description)

// listener and wrapper. ContextStore works fine when wrapper is stored in a field on original
// listener, but when listener class is a lambda instead of field it gets stored in a map with
// weak keys where original listener is key and wrapper is value. As wrapper has a strong
// reference to original listener this causes a memory leak.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// reference to original listener this causes a memory leak.
//
// also note that it's ok if the value is collected prior to the key, since this cache is only
// used to remove the wrapped listener from the netty future, and if the value is collected prior
// to the key, that means it's no longer used (referenced) by the netty future anyways

@laurit laurit closed this May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants