Permalink
Browse files

[fix] Don't emit the callback multiple times when shit goes wrong, fixes

 #68

The whole reconnection/failover logic should be redone, this is just silly..
  • Loading branch information...
1 parent 5ad99b7 commit 82eb7c9c8153af36c38841b93c30c0dd0024f495 @3rd-Eden committed Nov 27, 2012
Showing with 43 additions and 9 deletions.
  1. +1 −0 lib/connection.js
  2. +6 −9 lib/memcached.js
  3. +36 −0 test/memcached-connections.test.js
View
@@ -27,6 +27,7 @@ function IssueLog (args) {
this.failed = false;
this.totalRetries = 0;
+ this.retry = 0;
this.totalReconnectsAttempted = 0;
this.totalReconnectsSuccess = 0;
View
@@ -130,8 +130,8 @@ Client.config = {
*/
manager = new Jackpot(this.poolSize);
-
manager.retries = memcached.retries;
+
manager.factory(function factory() {
var S = Array.isArray(serverTokens)
? new Stream
@@ -155,9 +155,6 @@ Client.config = {
close: function streamClose() {
Manager.remove(this);
}
- , error: function streamError(err) {
- memcached.connectionIssue(err, S, callback);
- }
, data: curry(memcached, privates.buffer, S)
, timeout: function streamTimeout() {
Manager.remove(this);
@@ -259,7 +256,6 @@ Client.config = {
// check for issues
if (error) return query.callback && query.callback(error);
-
if (!S) return query.callback && query.callback('Connect did not give a server');
if (S.readyState !== 'open') {
@@ -293,10 +289,8 @@ Client.config = {
// Logs all connection issues, and handles them off. Marking all requests as
// cache misses.
- memcached.connectionIssue = function connectionIssue(error, S, callback) {
- // end connection and mark callback as cache miss
+ memcached.connectionIssue = function connectionIssue(error, S) {
if (S && S.end) S.end();
- if (callback) callback(false, false);
var issues
, server = S.serverAddress
@@ -341,6 +335,9 @@ Client.config = {
}
}
});
+
+ // bumpt the event listener limit
+ issues.setMaxListeners(0);
}
// log the issue
@@ -768,7 +765,7 @@ Client.config = {
flag = FLAG_JSON;
value = JSON.stringify(value);
}
-
+
value = Utils.escapeValue(value);
length = Buffer.byteLength(value);
@@ -0,0 +1,36 @@
+//global it
+
+'use strict';
+
+/**
+ * Test dependencies
+ */
+
+var assert = require('assert')
+ , fs = require('fs')
+ , common = require('./common')
+ , Memcached = require('../');
+
+global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed();
+
+/**
+ * Test connection issues
+ */
+describe('Memcached connections', function () {
+ it('should call the callback only once if theres an error', function (done) {
+ var memcached = new Memcached('127.0.1:1234', { retries: 3 })
+ , calls = 0;
+
+ this.timeout(60000);
+
+ memcached.get('idontcare', function (err) {
+ calls++;
+
+ // it should only be called once
+ assert.equal(calls, 1);
+
+ memcached.end();
+ done();
+ });
+ });
+});

0 comments on commit 82eb7c9

Please sign in to comment.