Skip to content

Memory leak in mongodb driver version 2.7 #978

Closed
@jakudlaty

Description

@jakudlaty

Versions/Environment

  1. rustc 1.73.0 (cc66ad468 2023-10-03)
  2. Gentoo Linux x64, on AMD Ryzen 5950
  3. https://github.com/rust-lang/crates.io-index#mongodb@2.7.0
  4. MongoDB version 7.0.2
  5. Topology standalone
  6. Empty database

Describe the bug

Memory usage grows constantly on driver version 2.7, here is simple example program:

pub use mongodb::{Client};
use mongodb::bson::doc;
use mongodb::options::ClientOptions;
use serde::{Deserialize, Serialize};

type OrderId = String;

#[derive(Serialize, Deserialize, Clone)]
pub struct OrderEntity {
    #[serde(rename = "_id")]
    pub id: OrderId,
}

#[tokio::main]
async fn main() {
    let options = ClientOptions::parse("mongodb://localhost:27017/memleak?authSource=admin&ssl=false&maxpoolsize=20").await.unwrap();
    let client = Client::with_options(options).unwrap();
    let database = client.default_database().unwrap();
    let orders = database.collection::<OrderEntity>("Orders");

    for _ in 0..10000000 {
        let _result = orders.find_one(doc! {"_id" : "12345"}, None).await.unwrap();
    }
}

my Cargo.toml kools like this:

[package]
name = "mongo-memleak-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
mongodb = "=2.7.0"

The X axis on graph is measured in seconds

See the graph below:
mem-graph-2 7

On version 2.6 memory looks perfectly fine:
mem-graph-2 6

Here is the full source code of working example https://github.com/jakudlaty/mongo-memleak-test/

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions