Commit d32f2736 authored by Arnout Kazemier's avatar Arnout Kazemier

Merge pull request #139 from ianshward/failures-limit

add failures time limit
parents 69347042 a999a435
......@@ -44,12 +44,20 @@ issues.log = function log (message) {
this.failed = true;
this.messages.push(message || 'No message specified');
// All failures must occur within `failuresTimeout` ms from the initial
// failure in order for node to be disconnected or removed.
if (this.failures && this.failures == this.config.failures)
this.failuresResetId = setTimeout(issue.failuresReset.bind(issue), this.failuresTimeout);
if (this.failures && !this.locked) {
this.locked = true;
setTimeout(issue.attemptRetry.bind(issue), this.retry);
return this.emit('issue', this.details);
}
if (this.failuresResetId) clearTimeout(this.failuresResetId);
if (this.remove) return this.emit('remove', this.details);
if (!this.isScheduledToReconnect) {
......@@ -58,6 +66,11 @@ issues.log = function log (message) {
}
};
issues.failuresReset = function failuresReset() {
//this.failures = this.config.failures;
Utils.merge(this, JSON.parse(JSON.stringify(this.config)));
};
Object.defineProperty(issues, 'details', {
get: function getDetails () {
var res = {};
......
......@@ -83,6 +83,7 @@ Client.config = {
, reconnect: 18000000 // if dead, attempt reconnect each xx ms
, timeout: 5000 // after x ms the server should send a timeout if we can't connect
, failures: 5 // Number of times a server can have an issue before marked dead
, failuresTimeout: 300000 // Time after which `failures` will be reset to original value, since last failure
, retry: 30000 // When a server has an error, wait this amount of time before retrying
, idle: 5000 // Remove connection from pool when no I/O after `idle` ms
, remove: false // remove server if dead if false, we will attempt to reconnect
......@@ -365,6 +366,7 @@ Client.config = {
, tokens: S.tokens
, reconnect: this.reconnect
, failures: this.failures
, failuresTimeout: this.failuresTimeout
, retry: this.retry
, remove: this.remove
});
......
......@@ -228,6 +228,30 @@ describe('Memcached connections', function () {
done();
});
});
});
it('should reset failures if all failures do not occur within failuresTimeout ms', function(done) {
var server = '10.255.255.255:1234'
, memcached = new Memcached(server, {
retries: 0,
timeout: 10,
idle: 1000,
retry: 10,
failures: 2,
failuresTimeout: 100 });
memcached.get('idontcare', function(err) {
assert.throws(function() { throw err }, /Timed out while trying to establish connection/);
// Allow `retry` ms to pass, which will decrement failures
setTimeout(function() {
assert.deepEqual(memcached.issues[server].failures, 1);
// Allow failuresTimeout ms to pass, which should reset failures
setTimeout(function() {
assert.deepEqual(memcached.issues[server].failures,
memcached.issues[server].config.failures);
memcached.end();
done();
}, 100);
}, 15);
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment