diff --git a/lib/db.js b/lib/db.js index 1166425..1c85f6b 100644 --- a/lib/db.js +++ b/lib/db.js @@ -86,10 +86,12 @@ module.exports.findUserByEmail = function (mail, callback) { r.db(dbConfig.db).table('users').filter({'mail': mail}).limit(1).run(connection, function(err, cursor) { if(err) { logerror("[ERROR][%s][findUserByEmail][collect] %s:%s\n%s", connection['_id'], err.name, err.msg, err.message); + connection.close(); callback(err); } else { cursor.next(function (err, row) { + connection.close(); if(err) { logerror("[ERROR][%s][findUserByEmail][collect] %s:%s\n%s", connection['_id'], err.name, err.msg, err.message); callback(err); @@ -97,7 +99,6 @@ module.exports.findUserByEmail = function (mail, callback) { else { callback(null, row); } - connection.close(); }); }