Skip to content

Commit

Permalink
fix redis#2010 - stop reconnect after .disconnect()
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale committed Nov 14, 2022
1 parent d097322 commit 3e20b34
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/client/lib/client/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
throw new Error('Socket already opened');
}

this.#isOpen = true;
return this.#connect();
}

Expand All @@ -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');
Expand All @@ -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> {
Expand Down Expand Up @@ -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
});
Expand All @@ -219,14 +221,17 @@ 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 = this.#isReady = false;

if (this.#socket) {
this.#socket.destroy();
this.#socket = undefined;
}

this.emit('end');
}

Expand Down

0 comments on commit 3e20b34

Please sign in to comment.