Skip to content

Commit 0214516

Browse files
committed
fix: handle unexpected socket closed
1 parent 8199f2b commit 0214516

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/client.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ export class RedisClient {
112112
})();
113113

114114
// Listen for socket close events and parse responses.
115-
this.#connection
116-
.then(async (connection) => {
115+
this.#connection.then(async (connection) => {
116+
let closed = false;
117+
connection.socket.closed.then(() => {
118+
closed = true;
119+
});
120+
121+
try {
117122
while (true) {
118123
const result = await connection.reader.read();
119124
if (!result) {
@@ -126,12 +131,12 @@ export class RedisClient {
126131
break;
127132
}
128133
}
129-
})
130-
.catch((error) => {
131-
if (error) {
134+
} catch (error) {
135+
if (!closed && this.#connection) {
132136
console.error(error);
133137
}
134-
});
138+
}
139+
});
135140

136141
if (this.config.password || this.config.database) {
137142
// AUTH and SELECT block all other commands until they are resolved.

0 commit comments

Comments
 (0)