Skip to content

Commit 16632f4

Browse files
committed
fix emitting internal auth error on reconnect
1 parent 50774ae commit 16632f4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features
99
Bugfixes
1010

1111
- Fixed not always copying subscribe unsubscribe arguments
12+
- Fixed emitting internal errors while reconnecting with auth
1213

1314
## v.2.7.1 - 14 Mar, 2017
1415

index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ function create_parser (self) {
228228
RedisClient.prototype.create_stream = function () {
229229
var self = this;
230230

231+
var first_attempt = !this.stream;
232+
231233
// Init parser
232234
this.reply_parser = create_parser(this);
233235

@@ -304,7 +306,13 @@ RedisClient.prototype.create_stream = function () {
304306
// Fire the command before redis is connected to be sure it's the first fired command
305307
if (this.auth_pass !== undefined) {
306308
this.ready = true;
307-
this.auth(this.auth_pass);
309+
// Fail silently as we might not be able to connect
310+
this.auth(this.auth_pass, function (err) {
311+
if (err && first_attempt) {
312+
self.command_queue.get(0).callback = noop;
313+
self.emit('error', err);
314+
}
315+
});
308316
this.ready = false;
309317
}
310318
};

test/auth.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ describe('client authentication', function () {
260260
password: 'wrong_password',
261261
parser: parser
262262
});
263-
client.once('error', function (err) {
263+
client.on('error', function (err) {
264264
assert.strictEqual(err.message, 'ERR invalid password');
265-
done();
265+
// Make sure no other errors are reported
266+
setTimeout(done, 50);
266267
});
267268
});
268269

0 commit comments

Comments
 (0)