From fe52ff1c6f4cb1beb0c9e999299248ba380d5cde Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Sun, 12 Feb 2023 08:36:39 +0800 Subject: [PATCH] fix: Fix commands not resend on reconnect in edge cases (#1720) Closes #1718 --- lib/redis/event_handler.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/redis/event_handler.ts b/lib/redis/event_handler.ts index 402c31c7..7625719c 100644 --- a/lib/redis/event_handler.ts +++ b/lib/redis/event_handler.ts @@ -155,19 +155,25 @@ function abortTransactionFragments(commandQueue: Deque) { export function closeHandler(self) { return function () { + const prevStatus = self.status; self.setStatus("close"); - if (!self.prevCondition) { - self.prevCondition = self.condition; - } if (self.commandQueue.length) { abortIncompletePipelines(self.commandQueue); - self.prevCommandQueue = self.commandQueue; } if (self.offlineQueue.length) { abortTransactionFragments(self.offlineQueue); } + if (prevStatus === "ready") { + if (!self.prevCondition) { + self.prevCondition = self.condition; + } + if (self.commandQueue.length) { + self.prevCommandQueue = self.commandQueue; + } + } + if (self.manuallyClosing) { self.manuallyClosing = false; debug("skip reconnecting since the connection is manually closed.");