Skip to content
Browse files

Fix regression in reconnect logic.

Very much need automated tests for reconnection and queue logic.
  • Loading branch information...
1 parent 5834f63 commit e39e8421bc5e7148312733a726e1a810696a8e11 @mranney mranney committed Nov 15, 2011
Showing with 22 additions and 17 deletions.
  1. +6 −0 changelog.md
  2. +14 −12 index.js
  3. +1 −1 package.json
  4. +1 −4 tests/reconnect_test.js
View
6 changelog.md
@@ -1,6 +1,12 @@
Changelog
=========
+## v0.7.1 - November 15, 2011
+
+Fix regression in reconnect logic.
+
+Very much need automated tests for reconnection and queue logic.
+
## v0.7.0 - November 14, 2011
Many contributed fixes. Thanks everybody.
View
26 index.js
@@ -33,7 +33,6 @@ function RedisClient(stream, options) {
this.connected = false;
this.ready = false;
this.connections = 0;
- this.attempts = 1;
this.should_buffer = false;
this.command_queue_high_water = this.options.command_queue_high_water || 1000;
this.command_queue_low_water = this.options.command_queue_low_water || 0;
@@ -48,9 +47,7 @@ function RedisClient(stream, options) {
if (options.connect_timeout && !isNaN(options.connect_timeout) && options.connect_timeout > 0) {
this.connect_timeout = +options.connect_timeout;
}
- this.retry_totaltime = 0;
- this.retry_delay = 250;
- this.retry_backoff = 1.7;
+ this.initialize_retry_vars();
this.subscriptions = false;
this.monitoring = false;
this.closing = false;
@@ -91,6 +88,14 @@ function RedisClient(stream, options) {
util.inherits(RedisClient, events.EventEmitter);
exports.RedisClient = RedisClient;
+RedisClient.prototype.initialize_retry_vars = function () {
+ this.retry_timer = null;
+ this.retry_totaltime = 0;
+ this.retry_delay = 250;
+ this.retry_backoff = 1.7;
+ this.attempts = 1;
+};
+
// flush offline_queue and command_queue, erroring any items with a callback first
RedisClient.prototype.flush_and_error = function (message) {
var command_obj;
@@ -194,10 +199,7 @@ RedisClient.prototype.on_connect = function () {
this.connections += 1;
this.command_queue = new Queue();
this.emitted_end = false;
- this.max_attempts = 0;
- this.retry_totaltime = 0;
- this.retry_timer = null;
- this.current_retry_delay = this.retry_delay;
+ this.initialize_retry_vars();
this.stream.setNoDelay();
this.stream.setTimeout(0);
@@ -373,7 +375,7 @@ RedisClient.prototype.connection_gone = function (why) {
return;
}
- this.current_retry_delay = this.current_retry_delay * this.retry_backoff;
+ this.retry_delay = Math.floor(this.retry_delay * this.retry_backoff);
if (exports.debug_mode) {
console.log("Retry connection in " + this.current_retry_delay + " ms");
@@ -387,8 +389,8 @@ RedisClient.prototype.connection_gone = function (why) {
return;
}
- self.attempts += 1;
- self.emit("reconnecting", {
+ this.attempts += 1;
+ this.emit("reconnecting", {
delay: self.retry_delay,
attempt: self.attempts
});
@@ -408,7 +410,7 @@ RedisClient.prototype.connection_gone = function (why) {
self.stream.connect(self.port, self.host);
self.retry_timer = null;
- }, this.current_retry_delay);
+ }, this.retry_delay);
};
RedisClient.prototype.on_data = function (data) {
View
2 package.json
@@ -1,5 +1,5 @@
{ "name" : "redis",
- "version" : "0.7.0",
+ "version" : "0.7.1",
"description" : "Redis client library",
"author": "Matt Ranney <mjr@ranney.com>",
"contributors": [
View
5 tests/reconnect_test.js
@@ -1,5 +1,5 @@
var redis = require("../index").createClient(null, null, {
- max_attempts: 2
+// max_attempts: 4
});
redis.on("error", function (err) {
@@ -13,9 +13,6 @@ redis.on("ready", function () {
redis.on("reconnecting", function (arg) {
console.log("Redis reconnecting: " + JSON.stringify(arg));
});
-redis.on("not_reconnecting", function (arg) {
- console.log("Redis NOT reconnecting: " + arg);
-});
redis.on("connect", function () {
console.log("Redis connected.");
});

0 comments on commit e39e842

Please sign in to comment.
Something went wrong with that request. Please try again.