Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves a bug with cluster where a subscribe is sent to a disconnected node #63

Merged
merged 1 commit into from
Jun 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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