Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Improve Redis client error logging to reduce log flooding

Bill Yang09ef09c89efa
diff --git a/server/src/db/redis/redis.ts b/server/src/db/redis/redis.ts
index ead957729..9e1fa50d7 100644
--- a/server/src/db/redis/redis.ts
+++ b/server/src/db/redis/redis.ts
@@ -20,8 +20,21 @@ function createRedisClient(label: string): Redis {
retryStrategy: (times: number) => Math.min(times * 200, 5000),
});
- client.on("error", (error: Error) => logger.error(error, `Redis client error (${label})`));
- client.on("connect", () => logger.info(`Redis connected (${label})`));
+ // ioredis emits an error on every failed reconnect attempt, which floods the
+ // logs while Redis is unreachable (e.g. local dev without Redis). Log only
+ // when the error changes; a successful connect re-arms logging so the next
+ // outage is still reported.
+ let lastLoggedError: string | undefined;
+ client.on("error", (error: Error) => {
+ const signature = `${(error as NodeJS.ErrnoException).code ?? ""}:${error.message}`;
+ if (signature === lastLoggedError) return;
+ lastLoggedError = signature;
+ logger.error(error, `Redis client error (${label}); suppressing repeats`);
+ });
+ client.on("connect", () => {
+ lastLoggedError = undefined;
+ logger.info(`Redis connected (${label})`);
+ });
return client;
}