From 6748ba5de33441d0bc3046f9eaf185769f4f34bf Mon Sep 17 00:00:00 2001 From: Leibale Date: Tue, 14 Nov 2023 19:57:47 -0500 Subject: [PATCH] fix #2632 - handle socket close in "socket initiator" phase --- packages/client/lib/client/socket.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/client/lib/client/socket.ts b/packages/client/lib/client/socket.ts index b079a51fea9..b701f6ea979 100644 --- a/packages/client/lib/client/socket.ts +++ b/packages/client/lib/client/socket.ts @@ -199,7 +199,7 @@ export default class RedisSocket extends EventEmitter { .off('error', reject) .once('error', (err: Error) => this.#onSocketError(err)) .once('close', hadError => { - if (!hadError && this.#isReady && this.#socket === socket) { + if (!hadError && this.#isOpen && this.#socket === socket) { this.#onSocketError(new SocketClosedUnexpectedlyError()); } }) @@ -229,10 +229,11 @@ export default class RedisSocket extends EventEmitter { } #onSocketError(err: Error): void { + const wasReady = this.#isReady; this.#isReady = false; this.emit('error', err); - if (!this.#isOpen || typeof this.#shouldReconnect(0, err) !== 'number') return; + if (!wasReady || !this.#isOpen || typeof this.#shouldReconnect(0, err) !== 'number') return; this.emit('reconnecting'); this.#connect().catch(() => {