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.");