Skip to content

Commit

Permalink
fix emitting internal auth error on reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed Jul 21, 2017
1 parent 50774ae commit 16632f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -9,6 +9,7 @@ Features
Bugfixes

- Fixed not always copying subscribe unsubscribe arguments
- Fixed emitting internal errors while reconnecting with auth

## v.2.7.1 - 14 Mar, 2017

Expand Down
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -228,6 +228,8 @@ function create_parser (self) {
RedisClient.prototype.create_stream = function () {
var self = this;

var first_attempt = !this.stream;

// Init parser
this.reply_parser = create_parser(this);

Expand Down Expand Up @@ -304,7 +306,13 @@ RedisClient.prototype.create_stream = function () {
// Fire the command before redis is connected to be sure it's the first fired command
if (this.auth_pass !== undefined) {
this.ready = true;
this.auth(this.auth_pass);
// Fail silently as we might not be able to connect
this.auth(this.auth_pass, function (err) {
if (err && first_attempt) {
self.command_queue.get(0).callback = noop;
self.emit('error', err);
}
});
this.ready = false;
}
};
Expand Down
5 changes: 3 additions & 2 deletions test/auth.spec.js
Expand Up @@ -260,9 +260,10 @@ describe('client authentication', function () {
password: 'wrong_password',
parser: parser
});
client.once('error', function (err) {
client.on('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password');
done();
// Make sure no other errors are reported
setTimeout(done, 50);
});
});

Expand Down

0 comments on commit 16632f4

Please sign in to comment.