Describe the bug Writing a big key which is almost equal or larger than the replica buffer limit size can trigger buffer overrun / psync loop. The replica won't be able to reconnect and stay connected unless the big keys is dropped from the backlog (and not other big key is written).

Replica client output buffer usage calculation is problematic and canlead to buffer overrun/psync loops

This can happen when a key almost equal or larger than the client output buffer limit of the replica is written.

To reproduce

  1. DB is empty
  2. Backlog size is 1 MB
  3. Client out put buffer limit is 2 MB
  4. Client writes a 3 MB key At this point the primary will drop the replica connection and will keep doing this (until the big key is removed from the backlog)

Expected behavior

The replica should not be disconnected if there's nothing to read from the primary.

Additional information

The buffer usage calculation is correct but problematic. Please see this PR for more info: https://github.com/redis/redis/pull/11666

Comment From: ranshid

the name "buffer overrun" is misleading. although the buffer might be "heavily" occupied it is not exceeding it allocated size (which implies memory overrun) I suggest to drop it from the title

@oranagra @xbasel ^