Loop icon
Sequential icon
RedisCLI icon
Docker icon
OutputValues icon
Log icon
Set icon
If icon
SlackIncomingWebhook icon
Pause icon
Fail icon
Schedule icon

Redis Client Output Buffer Guard

Catch Redis clients whose output buffer grows inside the server, alert Slack, then disconnect the offender with CLIENT KILL behind an approval.

Categories
DataInfrastructure

Redis buffers every reply per client. When a client reads slower than the server writes, the replies pile up in the server's own memory, not in the client. That is the normal state of a lagging pub/sub subscriber, a MONITOR left running by someone debugging or a replica on a thin link. It ends in one of two ways:

  • the buffer counts toward the instance memory and pushes it into maxmemory, where writes start failing or keys start being evicted;
  • the buffer crosses client-output-buffer-limit and Redis closes the client. For a pub/sub subscriber that is silent message loss, because pub/sub has no replay. For a replica it is a broken replication link that then needs a full resync.

None of this is visible on a memory graph, because the memory belongs to clients, not to keys. CLIENT LIST is where it shows: omem is the output buffer of one client, with the name and the command next to it.

This blueprint reads CLIENT LIST, CONFIG GET client-output-buffer-limit, INFO clients and INFO stats on every instance, puts each client in its own Redis class, then judges its omem against that class limit and against a KV baseline from the previous run. It alerts Slack. Behind an approval it can disconnect one named offender with CLIENT KILL, then read CLIENT LIST again and fail if the buffer is still there.

This blueprint was created by zkasuran.

Findings

Finding Severity Rule Offered fix
KILLED_ALREADY Critical client_output_buffer_limit_disconnections rose since the last run Report only, the client is already gone
NEAR_LIMIT Critical omem is at or over near_limit_pct of the hard limit for the client's class CLIENT KILL ID <id> ADDR <addr>
GROWING High omem rose by growth_mb or more since the last run, for the same client name CLIENT KILL ID <id> ADDR <addr>
REPLICA_BUFFER High A replica link is holding a reportable buffer Report only, a replica is never killed
UNCAPPED_BUFFER Medium omem is reportable and the class hard limit is 0, so Redis will never close it CLIENT KILL ID <id> ADDR <addr>
UNREACHABLE High No CLIENT LIST or CONFIG reply Report only

Safety

  • CLIENT KILL disconnects a live client, so it needs auto_remediate: true, dry_run: false and an approval through Pause. No answer within two hours means nothing is disconnected.
  • A replica link is never offered as a target, whatever its name. Killing one forces a resync.
  • Names in protected_names are never offered. Neither is the connection the guard is using itself.
  • The kill passes both ID and ADDR, which Redis treats as AND, so a client that reconnected between the report and the approval is not killed by mistake.
  • The remediation Loop runs with concurrencyLimit: 1.

How it works

  1. read (io.kestra.plugin.core.flow.Loop) runs CLIENT LIST, CONFIG GET client-output-buffer-limit, INFO clients and INFO stats on each host with io.kestra.plugin.redis.cli.RedisCLI, read-only. The inner Sequential has allowFailure: true, so one unreachable host is reported rather than fatal.
  2. assess parses the key=value fields of every CLIENT LIST line, puts each client in its Redis class (slave on the S flag, pubsub on a subscription or the P flag, else normal), reads the hard limit of that class out of the CONFIG reply, then compares omem with the limit and with the baseline. summary logs the result.
  3. save_baseline (io.kestra.plugin.core.kv.Set) stores the largest omem per client name, the obuf disconnection counter and client_recent_max_output_buffer. The baseline carries no TTL, because an expired KV key throws instead of reading as missing.
  4. route (io.kestra.plugin.core.flow.If):
    • clean: logs it.
    • findings: alert posts to Slack.
      • remediate_gate opens only when auto_remediate is true, dry_run is false and at least one finding is killable.
      • ask_approval posts the proposed targets and the resume link, wait_for_decision (io.kestra.plugin.core.flow.Pause) waits up to two hours for the addresses.
      • remediate (concurrencyLimit: 1) runs one CLIENT KILL ID <id> ADDR <addr> per approved client.
      • reread reads CLIENT LIST and INFO clients again. verify_result fails the run if an approved client is still connected with a reportable buffer.
  5. errors alerts Slack when the flow fails.

What you get

  • The output buffer of every client, attributed to a client name and a command, which is the part a memory graph cannot tell you.
  • The count of clients Redis has already closed for this, since the previous run, so silent pub/sub message loss stops being invisible.
  • Growth per client name between runs, so a buffer that is filling is caught before it is full.
  • One approved CLIENT KILL that frees the memory now, verified, with the reminder that it frees the symptom and not the cause.

Who it's for

  • Teams running Redis pub/sub, where a slow subscriber loses messages with no error anywhere.
  • Teams running replicas over a link that is sometimes slower than the write rate.
  • SREs who have watched used_memory climb with a flat keyspace and had nothing to point at.
  • Teams evaluating the Redis plugin who want an example of RedisCLI reading CLIENT LIST and acting on one client.

Why orchestrate this with Kestra

Output buffers grow in minutes and vanish when the client is closed, so there is usually nothing left to look at afterwards. Kestra samples CLIENT LIST on a schedule, keeps the previous sample in KV so growth and already-killed clients are both visible, then sends the offender's name to Slack. The disconnect is a real interruption for the client, so it sits behind auto_remediate, dry_run and an approval, with the re-read and the failure on an unchanged buffer in the same run. Every decision stays in the execution history.

Tested end to end

On Kestra 2.0.5 OSS against a Redis 7 container, with a real non-reading pub/sub subscriber named feed-fanout-worker (a raw socket that subscribes and never drains) and a replica frozen with docker pause. Every number below came out of redis-cli CLIENT LIST, INFO clients, INFO stats or INFO memory on the instance itself. A local HTTP sink stood in for Slack.

Run Inputs Result
healthy defaults 0 findings, clean logged. used_memory_human 1.15M, 1 client
detect defaults, subscriber stalled and 40 MB published CRITICAL NEAR_LIMIT feed-fanout-worker, 37 MiB, 396 replies queued, 58 percent of the 64 MiB pubsub hard limit. CLIENT LIST gave omem=39531808 for the same client and used_memory_human 38.86M
growth near_limit_pct: 95 after another 19 MB HIGH GROWING, omem=58541808, up 18 MiB against the baseline for the same client name. used_memory_human 56.99M
dry run auto_remediate: true, dry_run: true Same report, no approval asked, remediate_gate stayed closed. CLIENT LIST still showed omem=58541808
remediate auto_remediate: true, dry_run: false, resumed with the address CLIENT KILL replied 1, verify_result passed. The client was gone from CLIENT LIST and used_memory_human fell from 56.99M to 1.15M
already killed defaults, pubsub hard limit lowered to 256 KB and the flood repeated CRITICAL KILLED_ALREADY. client_output_buffer_limit_disconnections went 0 to 1 and CLIENT LIST was empty of the subscriber
replica auto_remediate: true, dry_run: false, replica frozen HIGH REPLICA_BUFFER on the flags=S link holding omem=47299040, no kill offered, the replica stayed online
uncapped pubsub hard limit set to 0 0 0 MEDIUM UNCAPPED_BUFFER, 37 MiB with no limit to cross
protected protected_names: feed-fanout-worker, remediation on Reported, no kill offered, the client stayed connected
unreachable a host that does not resolve HIGH UNREACHABLE for that host, the reachable one still reported
verify fails CLIENT KILL denied for the user with `ACL SETUSER default -client kill`
instance gone instance stopped while the approval was pending The CLIENT KILL task failed on the connection and the errors block posted to Slack

Prerequisites

  • Redis instances reachable from the Docker containers the RedisCLI tasks start. The user needs CLIENT LIST, CONFIG GET and INFO, plus CLIENT KILL for remediation. A NOPERM reply still exits 0, so a denied CLIENT LIST shows up as UNREACHABLE rather than as an error.
  • Set network to the Docker network your Redis containers are on when Kestra runs locally.
  • Local testing, a real non-reading subscriber:
    • docker run -d --name slow-sub --network <net> redis:7-alpine sh -c '(printf "CLIENT SETNAME feed-fanout-worker\r\nSUBSCRIBE ch\r\n"; sleep 7200) | nc <redis-host> 6379 | (sleep 7200)';
    • then publish a flood: redis-cli -r 400 publish ch "$(head -c 100000 /dev/zero | tr '\0' x)";
    • redis-cli CLIENT LIST now shows a growing omem on that client.

Secrets

  • SLACK_WEBHOOK_URL: used by alert, ask_approval and the errors block. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_SLACK_WEBHOOK_URL.

Inputs

Input Default Purpose
instances 2 example hosts Redis hosts to inspect
port 6379 Port on every host
near_limit_pct 50 Share of the class hard limit that counts as NEAR_LIMIT
min_omem_mb 1 Smallest output buffer worth reporting
growth_mb 1 Growth since the last run that counts as GROWING
protected_names empty Client names never offered for CLIENT KILL
network empty Docker network for the redis-cli containers
kestra_url http://localhost:8080 Used to build the resume link in the approval message
auto_remediate false Allow CLIENT KILL, which still waits for an approval
dry_run true Must be false for a change to apply

Quick start

  1. Add the SLACK_WEBHOOK_URL secret.
  2. Import the flow and list your instances in instances.
  3. Run it once with the defaults. The first run writes the baseline, so growth appears from the second run.
  4. Run it with auto_remediate: true and dry_run: false when you have an offender, then enter its address in the resume form.
  5. Enable the every_ten_minutes trigger, which always runs in safe mode.

How to extend

  • Give every service a CLIENT SETNAME on connect. Without it a finding can only name an address. The baseline also cannot follow the client across a reconnect.
  • Raise client-output-buffer-limit for the pubsub class when the burst is expected and the consumer is known to catch up, instead of disconnecting it.
  • Set maxmemory-clients (Redis 7 and later) so client memory has its own ceiling and Redis evicts the largest client rather than the keyspace.
  • Alert on client_recent_max_output_buffer crossing a threshold between two runs, which catches a spike that was already over before this flow sampled it.
  • Add password support with password: "{{ secret('REDIS_PASSWORD') }}" on each RedisCLI task.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.