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 long-lived connection pool #1081

Open
seanlinsley opened this issue Nov 13, 2023 · 2 comments
Open

Memory leak in long-lived connection pool #1081

seanlinsley opened this issue Nov 13, 2023 · 2 comments

Comments

@seanlinsley
Copy link

seanlinsley commented Nov 13, 2023

In the image below, memory usage is stable with prune_db_connections as described in bikeshedder/deadpool#273, plus malloc_trim(0). Then disabling prune_db_connections shows a clear memory leak.

Screenshot 2023-11-11 at 7 46 29 PM

Heaptrack shows two leaks, both around BytesMut usage:

Screenshot 2023-11-12 at 4 48 13 PM Screenshot 2023-11-12 at 5 12 03 PM

Related discussions online:

Possible debugging steps:

  • add code to track every message sent/received, where the buffer size has grown since the last message (might require a fork of the bytes crate)
  • write a reproduction script that's similar to the production workload (RDS, binary COPY FROM, queries that cause unique constraint error)

Possible fixes:

  • revert ffd7245
    • this would likely fix the leak if it's actually a bug in BytesMut usage and not something like closed connections never being freed. and it'd be a good opportunity to confirm/deny the performance difference that motivated the change originally
@sfackler
Copy link
Owner

Do you have a self contained reproduction?

@seanlinsley
Copy link
Author

seanlinsley commented Nov 13, 2023

I've tried to write a reproduction script, but it doesn't leak memory. If there is a bug in BytesMut usage it might be around the exact handling of messages sent/received to a remote database, using both regular queries (with heavy use of array binds) and binary COPY FROM, and with some queries resulting in unique constraint errors.

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

2 participants