Skip to content

Commit

Permalink
fix #2632 - handle socket close in "socket initiator" phase (#2653)
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale committed Nov 20, 2023
1 parent a8b81bd commit 68d835d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/client/lib/client/socket.ts
Expand Up @@ -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());
}
})
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 68d835d

Please sign in to comment.