Skip to content

Memory Leak of BalancedResolverGroup #412

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

Closed
johnsiu opened this issue May 31, 2021 · 4 comments
Closed

Memory Leak of BalancedResolverGroup #412

johnsiu opened this issue May 31, 2021 · 4 comments
Labels
type: bug A general bug
Milestone

Comments

@johnsiu
Copy link

johnsiu commented May 31, 2021

Bug Report

  • Driver: 0.8.8
  • Database: n/a
  • Java: n/a
  • OS: n/a

Current Behavior

Stack trace
// your stack trace here

Table schema

Input Code
-- your SQL here;

Steps to reproduce

Input Code
// your code here;

Expected behavior/code

We use this library in our project and found a memory leak.
Heap dumps were taken and it was discovered that there were many many instances of BalancedResolverGroup in EpollEventLoop.terminationFuture.listeners.listeners. It doesn't help that a new BalancedResolverGroup is created whenever a connection is acquired. Whenever BalancedResolverGroup.getResolver() is called, a new listener is added to the EventLoop's termination listeners.
see https://github.com/netty/netty/blob/netty-4.1.65.Final/resolver/src/main/java/io/netty/resolver/AddressResolverGroup.java#L89

Possible Solution

AddressResolverGroup should almost always be a singleton.
This line should use the static instance (BalancedResolverGroup.INSTANCE) rather than instantiating.
https://github.com/pgjdbc/r2dbc-postgresql/blob/v0.8.8.RELEASE/src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java#L392

Versions

Additional context

@johnsiu johnsiu added the status: waiting-for-triage An issue we've not yet triaged label May 31, 2021
@kitaev
Copy link

kitaev commented Jun 28, 2021

Hello @johnsiu

I have encountered this leak too. Did you manage to find a workaround besides patching r2dbc-postgres?

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 28, 2021
@kitaev
Copy link

kitaev commented Jun 28, 2021

@mp911de I think another option to fix this leak would be to call BalancedResolverGroup.close() in ReactorNettyClient.handleClose() method.

@mp911de
Copy link
Collaborator

mp911de commented Jun 28, 2021

Feel free to submit a pull request. Leaving BalancedResolverGroup open is clearly a bug on our side.

@mp911de mp911de added this to the 0.8.9.RELEASE milestone Jul 5, 2021
mp911de added a commit that referenced this issue Jul 5, 2021
We now also register a Shutdown hook to close BalancedResolverGroup.

[resolves #412]

Signed-off-by: Mark Paluch <[email protected]>
@mp911de mp911de closed this as completed in 06e6e85 Jul 5, 2021
@kaladhar-mummadi
Copy link

@mp911de
When Is 0.8.9 scheduled to be released ? We are facing the same issue.

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

No branches or pull requests

4 participants