Skip to content

Commit

Permalink
Resolves a bug with cluster where a subscribe is sent to a disconnect…
Browse files Browse the repository at this point in the history
…ed node
  • Loading branch information
devaos committed Jun 4, 2015
1 parent 9cdc5d1 commit 5257224
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ Cluster.prototype.createNode = function (port, host) {

var _this = this;
this.nodes[key].once('end', function () {
if (_this.subscriber === _this.nodes[key]) {
var deadNode = _this.nodes[key];
delete _this.nodes[key];
if (_this.subscriber === deadNode) {
_this.selectSubscriber();
}
delete _this.nodes[key];
if (Object.keys(_this.nodes).length === 0) {
_this.setStatus('close');
}
Expand All @@ -179,6 +180,10 @@ Cluster.prototype.selectRandomNode = function () {
};

Cluster.prototype.selectSubscriber = function () {
if (Object.keys(this.nodes).length === 0) {
this.subscriber = null;
return;
}
this.subscriber = this.selectRandomNode();
if (this.subscriber.status === 'wait') {
this.subscriber.connect().catch(function () {});
Expand Down Expand Up @@ -405,7 +410,6 @@ Cluster.prototype.getInfoFromNode = function (redis, callback) {
}
Object.keys(oldNodes).forEach(function (key) {
_this.nodes[key].disconnect();
delete _this.nodes[key];
});
callback();
}, 1000));
Expand Down

0 comments on commit 5257224

Please sign in to comment.