Skip to content

bug: memory leak in PgStream #3419

@OliverNChalk

Description

@OliverNChalk

Bug Description

  • 2024-08-08T19:10:15.458367Z: PgListener returns Error::Protocol(msg).
  • 1s later, our app's memory usage jumps from 0.033 GB to 1.32 GB according to netdata.
  • Memory remains at this level until the next time we receive Error::Protocol at which point it jumps again. Every occurrence seems to produce a memory increase of ~1.2 GB. This repeats on each Protocol error until OOM kill.

This is the protocol error msg:

unknown message type: '\\0'

I captured this memory flamegraph with heaptrack:

image

This implies that all of the 1.2GB of memory is being allocated by the PgConnection and not released. When we encounter a protocol error, we drop the PgListener instance and create a new one. Perhaps the Drop implementation of PgListener is failing to cleanup as the PgListener is in some sort of invalid state due to the protocol error?

Minimal Reproduction

Due to the protocol error, unable to reproduce minimally.

Info

  • SQLx version: v0.7.4
  • SQLx features enabled: [
    "chrono",
    "postgres",
    "runtime-tokio",
    "time",
    "tls-rustls",
    "bigdecimal",
    ]
  • Database server and version: Postgres 16.3 (with Timescale plugin)
  • Operating system: 22.04.1-Ubuntu
  • rustc --version: rustc 1.76.0 (07dca489a 2024-02-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions