Incident Response

Redis: client closed for overcoming of output buffer limits

Redis drops a client whose unread replies pile up past client-output-buffer-limit. For a replica that means a full sync that never finishes; for a Pub/Sub consumer, lost messages. How to tell which, and how to size the limits for a large dataset.

· 13 min read · AG Data Team

Redis: client scheduled to be closed ASAP for overcoming of output buffer limits is a warning in the Redis log, not an error a client sees. It means Redis had queued more unread replies for one connection than client-output-buffer-limit allows for that type of client, and dropped the connection to protect its own memory.

# Warning in the Redis log (shortened)
Client id=8812 addr=10.0.2.17:48212 ... flags=S ... omem=268435456 tot-mem=... cmd=psync ...
scheduled to be closed ASAP for overcoming of output buffer limits.

The interesting part is the client description in the middle. networking.c prints the same fields as CLIENT LIST: flags tells you the client type (S for a replica, P for a Pub/Sub subscriber, O for MONITOR), omem is the output buffer memory, and cmd is the last command. A line with flags=S and cmd=psync is a replica; that is the case that hurts most.

How the limit works

The redis.conf defines three client classes, each with a hard limit, a soft limit and a number of seconds:

client-output-buffer-limit normal  0     0    0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub  32mb  8mb  60

The same check also caps unauthenticated connections: in the current source, a client that has not authenticated yet is disconnected once more than 1024 bytes of replies are queued for it.

Case 1: a replica in a full sync loop

This is the classic incident. A replica connects and asks for a partial resync. If the primary's backlog no longer holds the data it is missing, the replication documentation describes what happens next: a full resynchronization. The primary forks to produce an RDB snapshot and buffers every new write for that replica until the snapshot has been transferred and loaded.

On a large dataset with steady writes, that buffer grows for the whole duration of the fork, the transfer and the load. With the default replica limits it is disconnected when it reaches 256MB, or when it stays above 64MB for 60 seconds. The replica reconnects, asks again, gets another full sync, and the loop starts over. Meanwhile the primary forks again and again, which costs CPU, memory and latency. In our experience this is one of the most common reasons a replica stays at master_link_status:down for hours after a restart or a network blip, while the primary's log fills with this warning.

The fix is to give that one sync enough room to finish:

# give replicas room during the next full sync (runtime, then persist)
redis-cli CONFIG SET client-output-buffer-limit "replica 1gb 512mb 120"
redis-cli CONFIG SET repl-backlog-size 256mb
redis-cli CONFIG REWRITE

Newer versions also move part of this buffering to the replica. In Redis 8.0 the primary can send the RDB file and the replication stream in parallel during a full sync, and replica-full-sync-buffer-limit limits how much the replica accumulates. Valkey has a similar option, dual-channel-replication-enabled, which is off by default and requires diskless sync on the primary. Either way, the primary's replica limit still applies once the replica stops accumulating.

Case 2: a slow Pub/Sub consumer

With flags=P the dropped client is a subscriber that reads messages more slowly than they are published. Pub/Sub has no persistence: the messages queued for that connection are gone, and anything published while it reconnects is missed. Raising the 32MB/8MB/60s limit only buys time; if the consumer is permanently slower than the producer, the buffer grows until it hits any limit you set, or until Redis runs out of memory. Fix the consumer (process in another thread, scale out), or use Redis Streams, where a consumer that falls behind can read later instead of losing data.

Case 3: normal clients and MONITOR

Normal clients are unlimited by default, so this warning for flags=N or flags=O means someone set a limit on the normal class. Without one, a client that requests a huge reply and reads it slowly, or a MONITOR session on a busy server, can make Redis hold a lot of memory for that connection. Large replies usually come from big keys or commands like KEYS *; a modest normal-class limit protects the server, at the cost of breaking clients that legitimately need large replies.

Raising limits is a memory decision. Output buffers are allocated on top of your dataset. Size maxmemory and the instance's RAM so that the replica limit times the number of replicas that may full-sync at once still fits, together with the extra memory a fork can use for copy-on-write.

Diagnosing it

# on the primary: is the replica stuck in full syncs?
redis-cli INFO stats | grep -E 'sync_full|sync_partial_ok|sync_partial_err|client_output_buffer_limit_disconnections'
redis-cli INFO replication
redis-cli INFO memory | grep -E 'used_memory_human|mem_clients_slaves|mem_clients_normal'

# who is holding large output buffers right now?
redis-cli CLIENT LIST TYPE pubsub
redis-cli CLIENT LIST TYPE replica

On large datasets

Everything in case 1 gets worse with size. A full sync of a 50GB dataset takes far longer than one of 2GB, so the replica buffer has to absorb many more writes, and every failed attempt costs another fork of a large process.

Key takeaways

Redis Valkey Replication Errors
Work with us

Redis replicas stuck in a sync loop?

We size Redis and Valkey replication buffers for large datasets, fix full sync loops and slow Pub/Sub consumers, and set up monitoring before they cause failovers.

Get in touch More from the blog