Skip to content

Commit ee88164

Browse files
author
Adam Kudybiński
committed
Fixes: redis#280
Make sure offline queue does not get flushed on subsequent reconnect attempts.
1 parent de66927 commit ee88164

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ RedisClient.prototype.on_error = function (msg) {
193193
this.connected = false;
194194
this.ready = false;
195195

196-
this.emit("error", new Error(message));
196+
try {
197+
this.emit("error", new Error(message));
198+
} catch (error) {
199+
this.flush_and_error(message);
200+
throw error;
201+
}
202+
197203
// "error" events get turned into exceptions if they aren't listened for. If the user handled this error
198204
// then we should try to reconnect.
199205
this.connection_gone("error");
@@ -483,11 +489,10 @@ RedisClient.prototype.connection_gone = function (why) {
483489
this.emitted_end = true;
484490
}
485491

486-
this.flush_and_error("Redis connection gone from " + why + " event.");
487-
488492
// If this is a requested shutdown, then don't retry
489493
if (this.closing) {
490494
this.retry_timer = null;
495+
this.flush_and_error("Redis connection gone from " + why + " event.");
491496
if (exports.debug_mode) {
492497
console.warn("connection ended from quit command, not retrying.");
493498
}
@@ -507,6 +512,7 @@ RedisClient.prototype.connection_gone = function (why) {
507512

508513
if (this.max_attempts && this.attempts >= this.max_attempts) {
509514
this.retry_timer = null;
515+
this.flush_and_error("Redis connection gone from " + why + " event.");
510516
// TODO - some people need a "Redis is Broken mode" for future commands that errors immediately, and others
511517
// want the program to exit. Right now, we just log, which doesn't really help in either case.
512518
console.error("node_redis: Couldn't get Redis connection after " + this.max_attempts + " attempts.");

0 commit comments

Comments
 (0)