Troubleshooting guide
Redis "max number of clients reached": how to fix it
Redis has reached its connection limit and is refusing new clients. Leaks and missing pooling are far more common than a limit that is genuinely too low.
3 min read10 sectionsUpdated
On this page
# Current and maximum
redis-cli INFO clients | grep connected_clients
redis-cli CONFIG GET maxclients
# Clients per source address
redis-cli CLIENT LIST | awk '{print $2}' | cut -d= -f2 | cut -d: -f1 | sort | uniq -c | sort -rn | head
# Long-idle connections
redis-cli CLIENT LIST | tr ' ' '\n' | grep '^idle=' | cut -d= -f2 | sort -n | tail -5
# Did Redis lower the limit at startup?
grep -i 'maxclients\|open files' /var/log/redis/redis-server.log | tailFixes
Reuse a single multiplexed client (Node ioredis, StackExchange.Redis) or a bounded pool. Create the client once at startup, never within a handler. Set timeout 300 in Redis so abandoned idle connections close. Raise maxclients with a matching file limit, using LimitNOFILE in systemd, if the count is legitimate. Consider a proxy such as Twemproxy for very large fleets.
Find the leak by shape
A leak has a recognisable pattern. Connections from one application rise steadily and only fall when that application restarts. On a chart this is a sawtooth aligned with deployments. Many connections from one address with high idle times indicate an unreturned pool or a client created per job. Set a client name with CLIENT SETNAME at connection time, so CLIENT LIST shows which service owns each connection, a small change that pays off the first time this happens.
Catch it automatically
Alert at 80 percent of maxclients in Redis monitoring, and treat a rising connection count without rising traffic as a leak. Log management can alert on the exact error message.
What is the default maxclients?
It is 10,000, unless the process file limit forces a lower value.
Do I need a connection pool for Redis?
Multiplexed clients work with a single connection. Use a pool for blocking commands or clients without multiplexing.
What does timeout do?
It closes client connections that have been idle longer than the given number of seconds.
Related reading
- ERR_CONNECTION_REFUSED: how to fix it: Fix ERR_CONNECTION_REFUSED in Chrome: nothing listening on the port, firewalls, wrong ports and localhost binding, with steps for visitors and for site owners.
- php-fpm "server reached pm.max_children": how to fix it: Fix php-fpm server reached pm.max_children: calculate the right worker count from memory, find slow scripts with the slow log and choose between pm modes.
- PostgreSQL "too many clients already": how to fix it: Fix PostgreSQL FATAL: sorry, too many clients already. See who holds connections, stop leaks, add PgBouncer and size max_connections the right way.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
- ERR_BLOCKED_BY_CLIENT: how to fix it: Fix net::ERR_BLOCKED_BY_CLIENT: ad blockers and privacy extensions blocking scripts, images and API calls, and how developers avoid false blocks.
- ERR_CONNECTION_CLOSED: how to fix it: Fix ERR_CONNECTION_CLOSED: servers closing connections early, TLS problems, firewalls, crashing apps and proxy timeouts, with checks for site owners.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.