Connection leak
Bug report
What is the bug?
When using r2d2-mongodb, connections are leaked, every time the idle_timeout
runs out and new connections are opened.
Depending on the number of connections in the pool and the idle timeout, this can quickly fill up the limit for the number of open files.
Version information
r2d2-mongodb version: 0.2.2
r2d2 version: 0.8.4
Operating system: Tested on a fresh install of Ubuntu 18.04.1 LTS
Steps to reproduce
Setup
Cargo.toml
[package]
name = "package"
version = "0.1.0"
authors = ["aticu"]
edition = "2018"
[dependencies]
r2d2 = "0.8.4"
r2d2-mongodb = "0.2.2"
src/main.rs
use std::{time::Duration, thread::sleep};
use r2d2::Pool;
use r2d2_mongodb::{ConnectionOptions, MongodbConnectionManager};
fn main () {
let manager = MongodbConnectionManager::new(
ConnectionOptions::builder()
.with_host("localhost", 27017)
.with_db("test")
.build()
);
let pool = Pool::builder()
.max_size(16)
// This is not strictly necessary, but speeds up the waiting time
.idle_timeout(Some(Duration::from_secs(5)))
.build(manager)
.unwrap();
loop {
sleep(Duration::from_secs(5));
}
}
Steps
- Start mongodb and run
cargo run
- Check the number of open connections with
lsof | grep package | grep localhost | grep -v LISTEN | wc -l
- Wait roughly 1 minute
- Check the number of connections again: It should have increased