Skip to content

Add --request-timeout to fail connections whose requests are never answered - #903

Merged
fcostaoliveira merged 6 commits into
redis:masterfrom
fcostaoliveira:fix/902-request-timeout
Nov 6, 2026
Merged

fcostaoliveira merged 6 commits into
redis:masterfrom
fcostaoliveira:fix/902-request-timeout

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #902.

A server that completes the TCP handshake but never serves the connection (e.g. a proxy that stopped calling accept() while throttling) leaves every request on it waiting for the whole run. Nothing errors, so --reconnect-on-error never fires, and --connection-timeout only bounds connect().

--request-timeout=SECS (a stall timeout, not a per-request deadline: a server that keeps sending data never trips it; values above INT_MAX are rejected) (0 = off, the default; behaviour unchanged unless set):

  • One watchdog timer per connection, armed by the first push after it went idle. It is an idle timeout driven by reply progress: any reply data read (or a request pushed to an idle pipeline) marks progress, and a window with requests outstanding and no progress is a timeout. No clocks and no per-request timestamps (so no wall-clock-step or shared-pipeline-timestamp false positives); the hot path costs one bool store, no event_add/event_del per op. A connection that never answers is detected after SECS; one that goes silent after answering, within SECS to 2*SECS.
  • An overdue connection is a connection error: Request timeout: no reply data for at least N seconds (M requests outstanding). on stderr, counted, and reconnected under --reconnect-on-error (otherwise the thread ends and the run fails, as for any lost connection). Setup commands (AUTH/HELLO/...) are covered too.
  • Note: getopt_long prefix matching means the abbreviation --request (formerly unique for --requests) is now ambiguous; the full names are unaffected.
  • Documented caveat: don't set it below the duration of a legitimately slow/blocking command.
  • Exposed in the config dump, JSON configuration, --help, man page, README, bash completion, CLI validation tests and the CLI fuzzer.

Not in this PR: the issue's second proposal (exit non-zero when a run completes 0 ops) — a separate behaviour change.

Tests (tests/test_request_timeout.py): non-accepting listener with and without --reconnect-on-error; a slow-but-answering server, a slow pipelined server (--pipeline=16), and an idle connection (no false timeout); skipped in the TLS/cluster cells; JSON config. Built and run on a c7i.16xlarge Ubuntu 24.04 VM.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core shard_connection reconnect and timer paths; misconfiguration could end runs or reconnect more often than intended, but default 0 preserves prior behavior.

Overview
Adds --request-timeout=SECS (default 0, off): when set, each connection gets a libevent stall watchdog—armed when work is pending, reset when reply data is read or a request wakes an idle pipeline—so peers that never answer after connect are treated like connection errors (logged, reconnect under --reconnect-on-error, else fail the run). Values above INT_MAX are rejected for timer safety.

Surfaces the option in help, man, README (including the --request / --requests ambiguity note), bash completion, config dump, and JSON output.

CI: legacy macOS OpenSSL 1.1 and 1.0.2 jobs move from macos-14 to macos-15 with an updated runner comment.

Tests: new tests/test_request_timeout.py plus CLI fuzz and validation updates.

Reviewed by Cursor Bugbot for commit dfbaa70. Bugbot is set up for automated code reviews on this repo. Configure here.

…nswered

A server that completes the TCP handshake but never serves the connection
(a proxy that stopped calling accept() while throttling) left every request
waiting for the rest of the run: nothing errors, so --reconnect-on-error never
fired, and --connection-timeout only bounds connect().

--request-timeout=SECS (0 = off, the default) arms one watchdog timer per
connection. When it fires it checks only the oldest outstanding request, so
replies cost no timer operation. An overdue request is treated as a connection
error: logged, counted, and reconnected under --reconnect-on-error (otherwise
the thread ends, as for any lost connection).

Fixes redis#902

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. I read through the watchdog and the tests, and the design looks sound to me. Having reply progress drive the timer, instead of per-request timestamps, avoids the pipelined-batch false positive, and the hot path stays at a branch plus a store. A few comments:

  • Naming / CLI compat. The PR already says --request stops being a unique abbreviation of --requests. Disclosing it is good, but I wonder if we need to break it at all. Your docs say this is "a stall timeout, not a per-request deadline", and --request-timeout reads like exactly the per-request deadline it isn't. Did you consider something like --reply-timeout or --stall-timeout? Either would describe the behaviour more accurately and would leave --request working for anyone who has it in scripts. Same kind of naming-precision question as the --tls-versions one in PR#234, and we've preferred the less-breaking option before when both were viable (PR#212).

  • push_req() ordering. The comment says the m_pending_resp check has to come before the fetch_add. That's correct, but it's easy to break in a later refactor. Would a local bool was_idle = m_pending_resp.load(...) == 0; captured before anything else make it harder to get wrong? Not blocking.

  • Detection window. If I read it right, a connection that answers once right after the timer is armed and then goes silent can take close to 2*SECS to be detected. You've documented that everywhere, so this is just to confirm it's intentional and not something you want to tighten (e.g. re-arm on the first progress after a fire).

  • test_cluster_connection_times_out_and_reconnects is the only test without _plain_standalone_only(). I guess that's because it uses the fake _Node harness like the rest of test_cluster_slots_bad_reply.py, so it runs the same in every cell? If so, fine.

  • Nitpicking: the macOS macos-14 → macos-15 runner change has nothing to do with the feature. I assume it's here to get CI green. It would probably be cleaner as its own small PR so the history reads clearly, but I wouldn't hold the PR for it.

The option checklist is complete (enum, long_options, switch, struct, help, man page, bash completion, fuzzer, validation tests), the default is off, and --max-reconnect-attempts still bounds a never-answering server because the counter only resets on a reply. The core change looks solid to me; mainly I'd like the naming question settled before this merges, since the flag name is hard to change once it ships.

(would file this as a comment, not a formal block)

fcostaoliveira and others added 5 commits November 6, 2026 14:21
The first version timed the oldest request from its wall-clock send time.
Requests pipelined in one batch share that time, so a slow server that kept
answering could be timed out, and a wall-clock step could time out every
healthy connection.

The watchdog now treats any reply data (or a request pushed to an idle
pipeline) as progress: a window with requests outstanding and no progress is
a timeout. No clocks and no per-request timestamps are involved; the hot path
costs one store. Detection takes SECS to 2*SECS after the last reply.

Also: skip the tests in the TLS and cluster CI cells, add a pipelined slow
server test, widen the timing margins, and document that setup commands are
covered.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Address review: the config comment and stderr line described the first
(per-request) version. Add a cluster-mode test where the node stalls the first
data request, and note that push_req() must test the pipeline before it counts
the new request.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Address review: say plainly that it is not a per-request deadline (a server
that keeps sending data never trips it), list the interactions (blocking
commands, --connection-stage-timeout, --rate-limiting, --retry-on-error, exit
code, the --request abbreviation), and reject values a 32-bit time_t cannot
hold.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The macos-14 runner pool is no longer provisioned: both jobs are cancelled
before any step runs with "The configuration 'macos-14-arm64-us-default' is
not supported".

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit ec95f3f into redis:master Nov 6, 2026
179 of 181 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No per-request reply timeout: a connection the server never serves stays stuck for the whole run, even with --reconnect-on-error

1 participant