Skip to content

pool.getConnection(function (error, connection) not returning a connection #405

Closed
@dannybisby

Description

@dannybisby

Hi,

Lately i've been experiencing an issue where pool.getConnection(function (error, connection) is not returning a function and is hanging any Express.js request i have that contains MySQL queries.

I've done debugging and tracked it back to this code.

The code i'm using is

var mysql = require('mysql'), sApp = null;

module.exports = {

connect : function (app, callback) {

    sApp = app;
    pool  = mysql.createPool({

        host     : app.config.mysql.hostname,
        user     : app.config.mysql.username,
        password : app.config.mysql.password,
        database : app.config.mysql.database,           
    });

    app.logging.info("Creating a new MySQL Pool");
    callback();
},

query : function (string, params, callback) {

    pool.getConnection(function (error, connection) {

        console.log(error);

        connection.query(string, params, function (error, rows) {

            connection.end();
            callback(error, rows);
        }); 
    });
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions