tediousjs/tedious-connection-pool

Memory leak when DB connection is temporarily lost.

yasen-atanasov opened this issue · 3 comments

Hi,

We had a brief DB outage which sent our app into a huge memory leak situation. Investigation showed that the connection pool, when unable to connect to the DB starts trying to create new connections to replace the failed ones sequentially, going into a loop and leaking a lot memory. This can be simulated by simply trying to connect to a DB with the wrong credentials. Here's the example code:

var ConnectionPool = require('tedious-connection-pool');
var pool = new ConnectionPool({ max: 150, min: 0 }, {
    "userName": "testLogin",
    "password": "wrongPassword",
    "server": "localhost",
    "options": {
        "port": 1433
    }
});

pool.acquire(function(err, connection_) {
    if (err) { return console.log("ERROR:", err); }
    console.log('no error');
});

The sequence of events seems to be:
PooledConnection handles the on 'end' event on the Tedious connection, calling self.connectionPool.pool.destroy(self)
which decrements the item count in the pool by 1, eventually going into negative numbers, and at the end calls ensureMinimum() which tries again and the loop continues.

Thank you for the report. I'll look into it tonight.

This issue and several others are fixed the v0.3.0 release.