Learning center

Redis max clients reached, or timeouts from a slow server?

A Redis error about the maximum number of clients means the server refused a new connection; a client-side timeout means a command took too long to answer. Read INFO clients and INFO stats first: a rising rejected_connections with connected_clients at maxclients points to the connection count, while a slow log full of long commands points to the server's single command thread. The fix differs, so tell them apart before you resize anything.

Two errors from the same cache#

Both appear in the same incident more often than you would expect:

  • New connections fail with ERR max number of clients reached. Redis writes this reply as a best effort and closes the socket, so the client logs a connection error, often during pool warmup or after a deploy. With cluster mode on, the message also mentions cluster connections. Over TLS, Redis refuses before the handshake and writes nothing, so the client sees only a dropped connection. Redis source, networking.c
  • Existing connections time out. The client library gives up after its own read timeout, and the log says something like "command timed out" with no reply from the server.

The first is a capacity limit on connections. The second is usually a server that cannot answer in time, or a network path that delays the answer. They feed each other: when commands slow down, clients hold connections longer and pools open more, which pushes the count toward the limit.

This guide is one of a set on runtime dependency failures.

How Redis counts clients#

maxclients defaults to 10,000. Redis also checks its process file descriptor limit at startup and lowers the effective limit if the operating system allows fewer descriptors than maxclients plus 32 reserved for internal use. On ElastiCache the parameter group sets maxclients to 65,000 for most node types. Redis client handling · ElastiCache engine parameters

In INFO, maxclients is the upper limit for the sum of connected_clients, connected_slaves and cluster_connections. rejected_connections counts connections refused because of that limit, and blocked_clients counts clients waiting in a blocking call such as BLPOP. INFO fields

Redis closes idle clients only if timeout is set; the default in redis.conf is timeout 0, so leaked connections from a client that never closes them stay open indefinitely. redis.conf · Client timeouts

The smallest read-only observations#

From a host that can reach the server, read the counters. These commands change nothing.

redis-cli -h REDIS_HOST -p 6379 INFO clients
redis-cli -h REDIS_HOST -p 6379 INFO stats | grep -E 'rejected_connections|total_connections_received|instantaneous_ops_per_sec'
redis-cli -h REDIS_HOST -p 6379 SLOWLOG GET 20
redis-cli -h REDIS_HOST -p 6379 --latency-history -i 5

The slow log records commands whose execution time exceeded slowlog-log-slower-than. That time excludes I/O such as reading the request and sending the reply; it is only the time the thread spent executing, during which it could serve nobody else. SLOWLOG GET

redis-cli --latency sends PING repeatedly and reports round trips in milliseconds from where you run it, and --latency-history starts a new sample every 15 seconds by default. Run it from the client's network, ideally from the client host itself. redis-cli latency modes · Diagnosing latency issues

To see who holds the connections, CLIENT LIST prints one line per connection with addr, age and idle. It is O(N) in the number of connections, so on a server near its limit run it once, not in a loop. CLIENT LIST

redis-cli -h REDIS_HOST -p 6379 CLIENT LIST \
  | awk '{split($2,a,"="); split(a[2],h,":"); print h[1]}' | sort | uniq -c | sort -rn | head

The latency monitor helps only if latency-monitor-threshold was already above 0; it is off by default. If it is on, LATENCY LATEST shows recent spikes by event. Latency monitoring

On ElastiCache, CONFIG is a restricted command, so read limits from INFO clients or the parameter group. CurrConnections is derived from connected_clients (ElastiCache uses 4 to 6 connections for monitoring), and NewConnections from total_connections_received. EngineCPUUtilization shows the load on the engine thread. Restricted commands · ElastiCache metrics

aws cloudwatch get-metric-statistics \
  --profile PROFILE --region REGION --namespace AWS/ElastiCache \
  --metric-name CurrConnections \
  --dimensions Name=CacheClusterId,Value=CACHE_CLUSTER_ID Name=CacheNodeId,Value=0001 \
  --statistics Maximum --period 60 \
  --start-time START --end-time END --no-cli-pager

Repeat with NewConnections and EngineCPUUtilization. get-metric-statistics · ElastiCache metric dimensions

Reading the numbers#

ObservationPoints to
connected_clients near maxclients, rejected_connections risingConnection limit
Many connections from a few addresses, large idleA client that leaks or over-provisions pools
NewConnections spikes during a rolloutOverlapping instances opening pools
Long entries in SLOWLOG GET, high engine CPUA slow server thread
--latency high, slow log emptyNetwork path or client side
High blocked_clients with low CPUBlocking calls waiting, often by design

A slow log with no long entries and a fast PING from the client host means the server answers quickly. The timeout then sits in the client: a pool exhausted while waiting for a free connection, a saturated event loop in the application, or a timeout set shorter than ordinary latency. Client or server latency

An illustrative incident with two outcomes#

This example is illustrative. The checkout service reads sessions from a Redis primary at 10.0.4.21. At 09:12 UTC its logs show both connection refusals and read timeouts.

In the first outcome, INFO clients shows connected_clients:9987 and maxclients:10000, and rejected_connections grows by about 40 a minute. CLIENT LIST grouped by address shows 7,900 connections from the twelve orders tasks, most with idle above 3,000 seconds. A release of orders at 08:10 created a client per request without closing it. The slow log holds nothing over 10 ms, and the timeouts in checkout are pools waiting for connections they cannot open. The capacity that ran out was connections, and the owner of the leak is orders.

In the second outcome, connected_clients is 1,200 and rejected_connections has not moved since startup. SLOWLOG GET shows KEYS session:* taking 1.8 seconds every minute from a new reporting job, and EngineCPUUtilization sits near 100%. Every command queued behind the scan waits, so clients time out and their pools open more connections. Removing the scan removes both symptoms. Raising maxclients would have changed nothing. Did a deploy overload the dependency?

Limits#

The slow log keeps a fixed number of entries (slowlog-max-len), so a busy server may have rotated the entries you need; read it while the incident is live. Execution time excludes I/O, so a server slowed by large replies or a saturated network interface can look fast in the slow log. SLOWLOG GET

INFO counters are cumulative since startup, so take two readings a minute apart and compare. A failover or restart resets them.

On ElastiCache Serverless, SLOWLOG, LATENCY and CLIENT LIST are not available; rely on the service metrics. Restricted commands

A memory limit produces a different error on writes. Redis OOM errors

Questions#

Does raising maxclients fix the max clients error?

Only if the connection count is legitimate. If a few hosts hold thousands of idle connections, raising the limit postpones the error and adds file descriptors and memory per client. Find who holds the connections with CLIENT LIST first.

Why do clients time out when the Redis slow log is empty?

The slow log measures only command execution on the server. Time spent in the network, in large replies or waiting for a free connection in the client pool does not appear there. Compare redis-cli --latency from the client host with the application's own timing.

Can I run CLIENT LIST on a busy server?

It reads state and changes nothing, but it is O(N) in the number of connections and runs on the same thread as other commands. Run it once rather than in a loop, and avoid it on a server already near its limit if a metric answers the question.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading