diff --git a/app/models/apikey_auth.js b/app/models/apikey_auth.js index 3d41dd97..e43b259a 100644 --- a/app/models/apikey_auth.js +++ b/app/models/apikey_auth.js @@ -37,15 +37,15 @@ module.exports = (function() { Step( function() { var step = this; - RedisPool.acquire(db, function(_redisClient) { + RedisPool.acquire(db, function(err, _redisClient) { + if ( err ) { step(err); return }; redisClient = _redisClient; redisArgs.push(step); redisClient[redisFunc.toUpperCase()].apply(redisClient, redisArgs); }); }, function releaseRedisClient(err, data) { - if (err) throw err; - RedisPool.release(db, redisClient); + if ( redisClient ) RedisPool.release(db, redisClient); callback(err, data); } ); diff --git a/app/models/metadata.js b/app/models/metadata.js index 518d3a5f..cd2ed8c3 100644 --- a/app/models/metadata.js +++ b/app/models/metadata.js @@ -59,13 +59,13 @@ module.exports = function() { function getRedisClient() { RedisPool.acquire(that.metadata_database, this); }, - function lookupMetadata(data) { + function lookupMetadata(err, data) { + if (err) throw err; redisClient = data; redisClient.HGET(redisKey, hashKey, this); }, function releaseRedisClient(err, data) { - if (err) throw err; - RedisPool.release(that.metadata_database, redisClient); + if ( redisClient ) RedisPool.release(that.metadata_database, redisClient); callback(err, data); } ); diff --git a/app/models/oauth.js b/app/models/oauth.js index fc36e8c8..2210fae4 100644 --- a/app/models/oauth.js +++ b/app/models/oauth.js @@ -130,11 +130,12 @@ var oAuth = function(){ me.getOAuthHash = function(access_key, callback){ var that = this; - RedisPool.acquire(this.oauth_database, function(client){ + RedisPool.acquire(this.oauth_database, function(err, client){ + if ( err ) { callback(err); return; } var redisClient = client; redisClient.HGETALL(_.template(that.oauth_user_key, {oauth_access_key: access_key}), function(err, data){ RedisPool.release(that.oauth_database, redisClient); - return callback(err, data) + callback(err, data); }); }); }; diff --git a/app/models/redis_pool.js b/app/models/redis_pool.js index b5b05a28..51bc5bff 100644 --- a/app/models/redis_pool.js +++ b/app/models/redis_pool.js @@ -6,13 +6,13 @@ var RedisPool = { // // - `database` {String} redis database name // - `callback` {Function} callback to call once acquired. Takes the form - // `callback(err, resource)` + // `callback(err, resource)` acquire: function(database, callback) { if (!this.pools[database]) { this.pools[database] = this.makePool(database); } - this.pools[database].acquire(function(resource) { - callback(resource); + this.pools[database].acquire(function(err, resource) { + callback(err, resource); }); }, @@ -52,4 +52,4 @@ var RedisPool = { } -module.exports = RedisPool; \ No newline at end of file +module.exports = RedisPool; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 2b2c6d61..0b2e4cad 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -186,15 +186,10 @@ }, "pg": { "version": "0.12.3-cdb1", - "from": "git://github.com/CartoDB/node-postgres.git#cdb_production", - "dependencies": { - "generic-pool": { - "version": "2.0.2" - } - } + "from": "git://github.com/CartoDB/node-postgres.git#cdb_production" }, "generic-pool": { - "version": "1.0.12" + "version": "2.0.3" }, "redis": { "version": "0.7.1" diff --git a/package.json b/package.json index 323f4e03..a756395f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "underscore.string": "1.1.5", "pg": "git://github.com/CartoDB/node-postgres.git#cdb_production", "express": "~2.5.11", - "generic-pool": "1.0.x", + "generic-pool": "~2.0.2", "redis": "0.7.1", "hiredis": "*", "step": "0.0.x", diff --git a/test/unit/redis_pool.test.js b/test/unit/redis_pool.test.js index aafb416e..1294f5d2 100644 --- a/test/unit/redis_pool.test.js +++ b/test/unit/redis_pool.test.js @@ -18,7 +18,8 @@ test('test pool object has an aquire function', function(){ }); test('test calling aquire returns a redis client object that can get/set', function(done){ - redis_pool.acquire(0, function(client){ + redis_pool.acquire(0, function(err, client){ + assert.ok(!err); client.set("key","value"); client.get("key", function(err,data){ assert.equal(data, "value"); @@ -29,12 +30,14 @@ test('test calling aquire returns a redis client object that can get/set', funct }); test('test calling aquire on another DB returns a redis client object that can get/set', function(done){ - redis_pool.acquire("MYDATABASE", function(client){ + redis_pool.acquire("MYDATABASE", function(err, client){ + assert.ok(!err); client.set("key","value"); client.get("key", function(err,data){ assert.equal(data, "value"); redis_pool.release("MYDATABASE", client); - redis_pool.acquire("MYDATABASE", function(client){ + redis_pool.acquire("MYDATABASE", function(err, client){ + assert.ok(!err); client.get("key", function(err,data){ assert.equal(data, "value"); redis_pool.release("MYDATABASE", client);