1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

ref #2524 - clear pingInterval timeout on close

This commit is contained in:
Leibale
2023-06-07 11:51:49 -04:00
parent cf79a806c5
commit b01f17709f

View File

@@ -825,6 +825,7 @@ export default class RedisClient<
*/ */
QUIT(): Promise<string> { QUIT(): Promise<string> {
return this._socket.quit(async () => { return this._socket.quit(async () => {
clearTimeout(this._pingTimer);
const quitPromise = this._queue.addCommand<string>(['QUIT']); const quitPromise = this._queue.addCommand<string>(['QUIT']);
this._tick(); this._tick();
return quitPromise; return quitPromise;
@@ -845,6 +846,7 @@ export default class RedisClient<
*/ */
close() { close() {
return new Promise<void>(resolve => { return new Promise<void>(resolve => {
clearTimeout(this._pingTimer);
this._socket.close(); this._socket.close();
if (this._queue.isEmpty()) { if (this._queue.isEmpty()) {
@@ -855,11 +857,11 @@ export default class RedisClient<
const maybeClose = () => { const maybeClose = () => {
if (!this._queue.isEmpty()) return; if (!this._queue.isEmpty()) return;
this._socket.off('data', maybeClose); this._socket.removeEventListener('data', maybeClose);
this._socket.destroySocket(); this._socket.destroySocket();
resolve(); resolve();
}; };
this._socket.on('data', maybeClose); this._socket.addEventListener('data', maybeClose);
}); });
} }
@@ -867,6 +869,7 @@ export default class RedisClient<
* Destroy the client. Rejects all commands immediately. * Destroy the client. Rejects all commands immediately.
*/ */
destroy() { destroy() {
clearTimeout(this._pingTimer);
this._queue.flushAll(new DisconnectsClientError()); this._queue.flushAll(new DisconnectsClientError());
this._socket.destroy(); this._socket.destroy();
} }