Closed
Description
Versions/Environment
- rustc 1.73.0 (cc66ad468 2023-10-03)
- Gentoo Linux x64, on AMD Ryzen 5950
- https://github.com/rust-lang/crates.io-index#mongodb@2.7.0
- MongoDB version 7.0.2
- Topology standalone
- 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
On version 2.6 memory looks perfectly fine:
Here is the full source code of working example https://github.com/jakudlaty/mongo-memleak-test/