Skip to content

Memory leak / unlimited caching kills the server #2372

@MartinKavik

Description

@MartinKavik

Bug Description

The connection (pool) "remembers" the query with the biggest memory size. It means when you insert some binary data (e.g. 100 MB) then it doesn't free the memory even though the data are already stored in the database.

I've tried to call persistent(false) or set various settings like max_lifetime but nothing really helped.

I've noticed the bug because my Rust app that uses sqlx through SeaORM was crashing on the server with the error "out of memory". The app uploads temporary binary data (~1-40MB) to Postgres and it allocates hundreds of MBs because of the sqlx bug until I set the maximum number of connections to a lower number with aggressive short lifetime and min_connections 0.

I've tried to debug it by myself by no luck unfortunately.

Minimal Reproduction

https://github.com/MartinKavik/sqlx-memory-debug
(instructions + a screenshot in the README)

Info

  • SQLx version: 0.6
  • SQLx features enabled: [ "runtime-tokio-rustls" , "postgres" ]
  • Database server and version: Postgres 13.5 or newer (other DBs not tested)
  • Operating system: desktop Kubuntu, server Ubuntu
  • rustc --version: rustc 1.67.1 (d5a82bbd2 2023-02-07)

Thank you!

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