debugMajor
Redis connection exhaustion — pool management and proper cleanup
Viewed 0 times
max clientsconnection poolioredisUpstashserverless redisconnection leak
nodejsdocker
Error Messages
Problem
Redis server stops accepting connections with max number of clients reached. Application gets ECONNREFUSED or timeout errors. Common in serverless and horizontally scaled environments.
Solution
Fixes: (1) Use connection pooling — ioredis has built-in pooling. (2) Always close connections in finally blocks. (3) In serverless: reuse connections across invocations by declaring client outside handler, or use Upstash REST-based Redis. (4) Set maxclients in redis.conf higher and monitor with INFO clients. (5) Set idle timeout: CONFIG SET timeout 300. (6) Check for leaks: CLIENT LIST to see all connections.
Why
Each Redis connection consumes a file descriptor and memory. Without pooling, each request creates a new connection. Serverless functions are especially prone because each cold start creates a new connection.
Revisions (0)
No revisions yet.