1

I am using node for my project and using connection pooling, whenever I query show processlist I found more than 200 sleep connections even though i am releasing it after every query like this-

    return new Promise((resolve, reject) => {

    sql.getConnection(function (err, conn) {
        if (err) {
            conn.release();
            reject(err)
        }
        conn.query('QUERY', function (err, rows) {
            conn.release();
            if (err) {
                reject(err)
            }
            else {
                resolve(rows[0])
            }
        })
    })
})

Still i found 200 plus sleep connections. Is there any way to kill useless sleeps connection through node? Or is it fine having so many sleep connections?

Thanks in advance!

ADITYA HAZARIKA
  • 300
  • 1
  • 4
  • 13

1 Answers1

0

If you are using connection pooling, you will need to close all the connections in the pool when you're finished using them. Otherwise the connections will stay open until they are closed by the MySQL server.

pool.end(function (err) {
  // all connections in the pool have ended
});

This GitHub issue explains a little more about the nuance between releasing a connection (conn.release()) and closing the underlying connection pool (pool.end()).

Daniel Bank
  • 3,581
  • 3
  • 39
  • 50