Skip to content

Commit 13ad249

Browse files
authored
fix #2010 - stop reconnect after .disconnect() (#2323)
* fix #2010 - stop reconnect after .disconnect() * fix quit
1 parent 28b9701 commit 13ad249

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

packages/client/lib/client/socket.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
105105
throw new Error('Socket already opened');
106106
}
107107

108+
this.#isOpen = true;
108109
return this.#connect();
109110
}
110111

@@ -116,7 +117,6 @@ export default class RedisSocket extends EventEmitter {
116117
}
117118

118119
try {
119-
this.#isOpen = true;
120120
this.#socket = await this.#createSocket();
121121
this.#writableNeedDrain = false;
122122
this.emit('connect');
@@ -142,7 +142,7 @@ export default class RedisSocket extends EventEmitter {
142142
await promiseTimeout(retryIn);
143143
}
144144
retries++;
145-
} while (!this.#isReady);
145+
} while (this.#isOpen && !this.#isReady);
146146
}
147147

148148
#createSocket(): Promise<net.Socket | tls.TLSSocket> {
@@ -203,6 +203,8 @@ export default class RedisSocket extends EventEmitter {
203203
this.#isReady = false;
204204
this.emit('error', err);
205205

206+
if (!this.#isOpen) return;
207+
206208
this.#connect(true).catch(() => {
207209
// the error was already emitted, silently ignore it
208210
});
@@ -219,14 +221,22 @@ export default class RedisSocket extends EventEmitter {
219221
}
220222

221223
disconnect(): void {
222-
if (!this.#socket) {
224+
if (!this.#isOpen) {
223225
throw new ClientClosedError();
224-
} else {
225-
this.#isOpen = this.#isReady = false;
226226
}
227227

228-
this.#socket.destroy();
229-
this.#socket = undefined;
228+
this.#isOpen = false;
229+
this.#disconnect();
230+
}
231+
232+
#disconnect(): void {
233+
this.#isReady = false;
234+
235+
if (this.#socket) {
236+
this.#socket.destroy();
237+
this.#socket = undefined;
238+
}
239+
230240
this.emit('end');
231241
}
232242

@@ -237,7 +247,7 @@ export default class RedisSocket extends EventEmitter {
237247

238248
this.#isOpen = false;
239249
await fn();
240-
this.disconnect();
250+
this.#disconnect();
241251
}
242252

243253
#isCorked = false;

0 commit comments

Comments
 (0)