Skip to content

Commit 5b6c6e2

Browse files
committed
fix: catch read errors and log them
1 parent cd494c6 commit 5b6c6e2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/client.ts

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

114114
// Listen for socket close events and parse responses.
115-
this.#connection.then(async (connection) => {
116-
try {
115+
this.#connection
116+
.then(async (connection) => {
117117
while (true) {
118-
const result = await Promise.race([
119-
connection.socket.closed,
120-
connection.reader.read(),
121-
]);
118+
const result = await connection.reader.read();
122119
if (!result) {
123120
break;
124121
}
@@ -129,10 +126,12 @@ export class RedisClient {
129126
break;
130127
}
131128
}
132-
} finally {
133-
await this.close();
134-
}
135-
});
129+
})
130+
.catch((error) => {
131+
if (error) {
132+
console.error(error);
133+
}
134+
});
136135

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

0 commit comments

Comments
 (0)