Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: instantiate the ratelimit redis client on first use to avoid connection errors (#5362)

Steffen Schmitz016993c117bd
diff --git a/web/src/features/public-api/server/RateLimitService.ts b/web/src/features/public-api/server/RateLimitService.ts
index 3c8674ad9b..c5d4a51f1f 100644
--- a/web/src/features/public-api/server/RateLimitService.ts
+++ b/web/src/features/public-api/server/RateLimitService.ts
@@ -34,6 +34,7 @@ export class RateLimitService {
createNewRedisInstance({
enableAutoPipelining: false, // This may help avoid https://github.com/redis/ioredis/issues/1931
enableOfflineQueue: false,
+ lazyConnect: true, // Connect when first command is sent
...redisQueueRetryOptions,
});
RateLimitService.instance = new RateLimitService();
@@ -83,6 +84,15 @@ export class RateLimitService {
return;
}
+ // Connect Redis if not initialized
+ if (RateLimitService?.redis?.status !== "ready") {
+ try {
+ await RateLimitService?.redis?.connect();
+ } catch (err) {
+ // Do nothing here. We will fail open if Redis is not available.
+ }
+ }
+
const rateLimiter = new RateLimiterRedis({
// Basic options
points: effectiveConfig.points, // Number of points