Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql connections number keep growing even using db.close() #795

Open
zjhsdtc opened this issue Jun 28, 2017 · 0 comments
Open

Mysql connections number keep growing even using db.close() #795

zjhsdtc opened this issue Jun 28, 2017 · 0 comments

Comments

@zjhsdtc
Copy link

zjhsdtc commented Jun 28, 2017

Hi, I'm just struggling with this issue for hours and I think I can not figure it out by myself, so I put this question here. I got some database operation functions like below, and the problem is even I use db.close() after the query is finished, every time when queryAllThreads is invoked, the number of connections in mysql database is still keep growing and never decrease its number, so am I missing anything in the document to close the database connection? How can I fix this because I will invoke this query function every minute, and it will reach the maximum number of database connections in a relatively short time. Thanks in advance!

var opts = {
    host: dbhost,
    database: dbname,
    user: dbuser,
    password: dbpass,
    protocol: 'mysql',
    port: dbport,
    query: {pool: true, debug: true}
}

var threadModel = {
    websiteUrl: String,
    threadUrl: { type: 'text', big: true },
    username: String,
    password: String,
    schedule: { type: 'text' },
    content: { type: 'text', big: true },
    remark: String,
    createTime: String,
    createTs: { type: 'integer' },
    updateTime: String,
    updateTs: { type: 'integer' }
}

exports.queryAllThreads = function (callback) {
    orm.connect(opts, function (err, db) {
        var threads = db.define("threads", threadModel);
        db.sync(function (err) {
            if (!err) {
                threads.find({}, function (err, results) {
                    db.close();
                    if (err) {
                        console.log("error when query threads => " + err);
                    } else {
                        callback(results);
                    }
                });
            }
        });
    });
}

screen shot 2017-06-29 at 1 30 32 am

@zjhsdtc zjhsdtc changed the title Mysql connections keep growing even close the db Mysql connections number keep growing even using db.close() Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant