Currently my process is hanging because the mysql pool isn't being closed automatically.
I assumed that when I called connection.release()
the connection would get closed if no one else was using it. But it seems that is not the case. My code looks like:
getConnection.js:
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 10,
host : 'localhost',
user : 'root',
password : 'mysql',
database : 'xxx'
});
module.exports = function getConnection(callback){
pool.getConnection(function(err, connection){
if (err) {
throw err;
}
callback(connection);
});
}
And i'm using it like this:
var getConn = require('./getConnection');
function selectOne(query, map, cb){
getConn(function(conn){
conn.query(query, map, function(err, rows){
if (err) {
throw err;
}
cb(rows.length ? rows[0] : false);
conn.release();
});
});
}
I think I'm missing something. Shouldn't node-mysql close the connection for me when I release it?