keepwalking
keepwalking

Reputation: 2654

Node.js, ORM2 and Mysql. Connection are not closing

I am using node.js, express, ORM2 and Mysql. Everytime a page loads a new mysql connection is opened. The issue here is that the connection doesn't close, it stays open. So, each requests result a new "sleep" status connection in my mysql "show processlist" command.

Thanks, Radu

Upvotes: 0

Views: 473

Answers (1)

keepwalking
keepwalking

Reputation: 2654

Actually because i am new at node i did not realize that my application never ends the execution and i have to use singleton method for the mysql connection.

Using something like:

if (connection) return cb(null, connection);
orm.connect(settings.database, function (err, db) {
    if (err) return cb(err);
    connection = db;
    db.settings.set('instance.returnAllErrors', true);
    setup(db, cb);  
});

This will keep just one mysql connection open.

Upvotes: 1

Related Questions