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

fix #2010 - stop reconnect after .disconnect() (#2323)

* fix #2010 - stop reconnect after .disconnect()

* fix quit
This commit is contained in:
Leibale Eidelman
2022-11-24 14:03:34 -05:00
committed by GitHub
parent 28b9701543
commit 13ad249ae6

View File

@@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
throw new Error('Socket already opened');
}
this.#isOpen = true;
return this.#connect();
}
@@ -116,7 +117,6 @@ export default class RedisSocket extends EventEmitter {
}
try {
this.#isOpen = true;
this.#socket = await this.#createSocket();
this.#writableNeedDrain = false;
this.emit('connect');
@@ -142,7 +142,7 @@ export default class RedisSocket extends EventEmitter {
await promiseTimeout(retryIn);
}
retries++;
} while (!this.#isReady);
} while (this.#isOpen && !this.#isReady);
}
#createSocket(): Promise<net.Socket | tls.TLSSocket> {
@@ -203,6 +203,8 @@ export default class RedisSocket extends EventEmitter {
this.#isReady = false;
this.emit('error', err);
if (!this.#isOpen) return;
this.#connect(true).catch(() => {
// the error was already emitted, silently ignore it
});
@@ -219,14 +221,22 @@ export default class RedisSocket extends EventEmitter {
}
disconnect(): void {
if (!this.#socket) {
if (!this.#isOpen) {
throw new ClientClosedError();
} else {
this.#isOpen = this.#isReady = false;
}
this.#socket.destroy();
this.#socket = undefined;
this.#isOpen = false;
this.#disconnect();
}
#disconnect(): void {
this.#isReady = false;
if (this.#socket) {
this.#socket.destroy();
this.#socket = undefined;
}
this.emit('end');
}
@@ -237,7 +247,7 @@ export default class RedisSocket extends EventEmitter {
this.#isOpen = false;
await fn();
this.disconnect();
this.#disconnect();
}
#isCorked = false;