Skip to content

Memory leak in long-lived connection pool #1081

Open
@seanlinsley

Description

@seanlinsley

In the image below, memory usage is stable with prune_db_connections as described in deadpool-rs/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions