1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix #2632 - handle socket close in "socket initiator" phase (#2653)

This commit is contained in:
Leibale Eidelman
2023-11-20 13:16:36 -05:00
committed by GitHub
parent a8b81bdd01
commit 68d835d7a2

View File

@@ -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(() => {