Skip to content

Commit 68d835d

Browse files
authored
fix #2632 - handle socket close in "socket initiator" phase (#2653)
1 parent a8b81bd commit 68d835d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/client/lib/client/socket.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class RedisSocket extends EventEmitter {
199199
.off('error', reject)
200200
.once('error', (err: Error) => this.#onSocketError(err))
201201
.once('close', hadError => {
202-
if (!hadError && this.#isReady && this.#socket === socket) {
202+
if (!hadError && this.#isOpen && this.#socket === socket) {
203203
this.#onSocketError(new SocketClosedUnexpectedlyError());
204204
}
205205
})
@@ -229,10 +229,11 @@ export default class RedisSocket extends EventEmitter {
229229
}
230230

231231
#onSocketError(err: Error): void {
232+
const wasReady = this.#isReady;
232233
this.#isReady = false;
233234
this.emit('error', err);
234235

235-
if (!this.#isOpen || typeof this.#shouldReconnect(0, err) !== 'number') return;
236+
if (!wasReady || !this.#isOpen || typeof this.#shouldReconnect(0, err) !== 'number') return;
236237

237238
this.emit('reconnecting');
238239
this.#connect().catch(() => {

0 commit comments

Comments
 (0)