From 673460dee1dc91a2743e93bea6e3e7c125be26f0 Mon Sep 17 00:00:00 2001 From: xuyang Date: Fri, 19 May 2017 16:13:47 +0800 Subject: [PATCH 1/3] update redis monitor reconnect on slave error --- lib/monitors/redismonitor.js | 18 +++++++++++------- package.json | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/monitors/redismonitor.js b/lib/monitors/redismonitor.js index 8d78ae286..e8163cab1 100644 --- a/lib/monitors/redismonitor.js +++ b/lib/monitors/redismonitor.js @@ -19,6 +19,10 @@ var Monitor = function(app, opts) { this.expire = opts.expire || constants.TIME.DEFAULT_REDIS_EXPIRE; this.password = opts.password || null; this.redisOpts = opts.redisOpts || {}; + this.redisOpts.reconnectOnError = function(err) { + if (err.message.indexOf('READONLY') !== -1) + return true; + }; }; module.exports = Monitor; @@ -70,9 +74,9 @@ Monitor.prototype.start = function(cb) { }; Monitor.prototype.stop = function() { - this.client.end(); + this.client.disconnect(); if (!!this.pingRedis) { - this.pingRedis.end(); + this.pingRedis.disconnect(); } clearInterval(this.timer); }; @@ -179,14 +183,14 @@ var getMaster = function(self, redisNodes) { ping(self, client, redis); }, constants.TIME.DEFAULT_REDIS_PING); } else { - client.end(); + client.disconnect(); client = null; } }); }); client.on('error', function() { logger.error('[redisMonitor] monitor redis connect error'); - client.end(); + client.disconnect(); client = null; }); })(i); @@ -199,10 +203,10 @@ var ping = function(self, client, rds) { clearInterval(self.pingtimer); if(self.pingtimer) { logger.info('[redisMonitor] clear pingtimer timeout'); - client.end(); + client.disconnect(); client = null; self.pingtimer = null; - rds.end(); + rds.disconnect(); rds = null; self.start(function() {}); } @@ -221,7 +225,7 @@ var clearPingTimer = function(self, cb) { clearInterval(self.pingtimer); var client = self.pingRedis; if(!!client) { - client.end(); + client.disconnect(); client = null; self.pingtimer = null; } diff --git a/package.json b/package.json index dfbd15c3f..53a986f9f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "mqtt": "0.3.9", "node-zookeeper-client": "0.2.2", "node-uuid": "1.4.3", - "ioredis": "1.10.0", + "ioredis": "2.5.0", "redis": "0.12.1" }, "bin": { From 1eb91c8b17c0886d6e1f31acc0584ea59d39c938 Mon Sep 17 00:00:00 2001 From: xuyang Date: Mon, 12 Jun 2017 17:37:46 +0800 Subject: [PATCH 2/3] update version to 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 53a986f9f..acaa677dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pomelo", - "version": "2.0.0", + "version": "2.0.1", "private": false, "homepage": "https://github.com/NetEase/pomelo", "repository": { From 1b60e6647c61334451606523a7def79429638235 Mon Sep 17 00:00:00 2001 From: xuyang Date: Tue, 13 Jun 2017 15:09:11 +0800 Subject: [PATCH 3/3] fix bug in redis client disconnect --- lib/monitors/redismonitor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/monitors/redismonitor.js b/lib/monitors/redismonitor.js index e8163cab1..68144cde7 100644 --- a/lib/monitors/redismonitor.js +++ b/lib/monitors/redismonitor.js @@ -76,7 +76,7 @@ Monitor.prototype.start = function(cb) { Monitor.prototype.stop = function() { this.client.disconnect(); if (!!this.pingRedis) { - this.pingRedis.disconnect(); + this.pingRedis.end(); } clearInterval(this.timer); }; @@ -183,14 +183,14 @@ var getMaster = function(self, redisNodes) { ping(self, client, redis); }, constants.TIME.DEFAULT_REDIS_PING); } else { - client.disconnect(); + client.end(); client = null; } }); }); client.on('error', function() { logger.error('[redisMonitor] monitor redis connect error'); - client.disconnect(); + client.end(); client = null; }); })(i); @@ -203,7 +203,7 @@ var ping = function(self, client, rds) { clearInterval(self.pingtimer); if(self.pingtimer) { logger.info('[redisMonitor] clear pingtimer timeout'); - client.disconnect(); + client.end(); client = null; self.pingtimer = null; rds.disconnect(); @@ -225,7 +225,7 @@ var clearPingTimer = function(self, cb) { clearInterval(self.pingtimer); var client = self.pingRedis; if(!!client) { - client.disconnect(); + client.end(); client = null; self.pingtimer = null; }