Skip to content

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

Description

@zjhsdtc

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

Activity

  1. changed the title [-]Mysql connections keep growing even close the db[/-] [+]Mysql connections number keep growing even using `db.close()`[/+] on Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions