Skip to content

Bound the CLIENT KILL loop in test_ask_retry_waits_for_reconnect - #758

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/680-ask-reconnect-flake
Oct 17, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/680-ask-reconnect-flake

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

tests/test_cluster_ask_asking.py::test_ask_retry_waits_for_reconnect sometimes fails with subprocess.TimeoutExpired (60 s) on sanitizer jobs (#680). It failed again on PR #748 at 316559b, in "UBSan OSS-CLUSTER API: TCP Plaintext" (job 117247837036). The log has only the traceback, because the test threw away memtier's stderr when it timed out. This is item 4 in #740.

Root cause: the test, not memtier

  • The test ran CLIENT KILL TYPE normal on the importing node every 0.5 s for the whole memtier run.
  • memtier reconnects 1 s after each drop (--reconnect-backoff-factor=1).
  • The -ASK retries that wait for that node fill both clients' --pipeline 8. They complete only when a reconnect, its setup (slot-map refresh, connect) and the resends all fit between two kills.
  • So the run time had no upper bound. It depends on how the reconnect timing lines up with the 0.5 s kill grid, and that gets worse when setup is slow (sanitizers, a loaded runner).

memtier does not hang. To rule out a real hang I ran the old test under ASan+UBSan (--enable-sanitizers --enable-ubsan), with 5 copies pinned to one CPU and 3 CPU burners on that same CPU:

  • Every slow run kept making progress, at about 20-80 ops per reconnect window, until it finished.
  • With the killer bounded, every run ends about 2 s after the last kill. That would not happen if memtier were stuck.

Fix (test only)

  • Kill only the connections opened after the killer took its snapshot of the client list. These are memtier's connections, killed by CLIENT KILL ID.
  • Stop after KILL_WAVES = 5 rounds that each dropped at least one memtier connection.
  • Assert that at least one memtier connection was dropped, so the scenario cannot silently become a no-op.
  • Write memtier's stderr to a file instead of a pipe. On failure or timeout, print its tail and the run time, so a real hang would show up in CI.

There are no C++ changes, so this does not interact with #666 or #750. Neither of them touches this test.

Evidence (ASan+UBSan build of origin/master 63c0009, 3-shard oss-cluster)

runs failures memtier run time
old test, 5 parallel on 1 CPU 20 0 4.1-15.2 s
old test, 5 parallel on 1 CPU + 3 burners 20 0 5.2-17.4 s (median ~10 s)
new test, 5 parallel on 1 CPU + 3 burners 30 0 4.8-8.4 s
new test, #597 fix reverted (mutant), 2 and 1 CPU 15 15 each fails with 25-86 requests ending on -ASK

Affected versions

Test suite / CI only. The test was introduced by 3822415 (#600), which is not in any release tag (latest is 2.5.2). Release binaries are not affected.

Fixes #680
Refs #740

🤖 Generated with Claude Code


Note

Low Risk
Test-only changes to cluster ASK/reconnect coverage; no production or memtier binary behavior changes.

Overview
Stabilizes test_ask_retry_waits_for_reconnect by capping connection drops and improving failure diagnostics when memtier runs under repeated CLIENT KILL during cluster -ASK retries.

The killer no longer loops for the entire benchmark: it snapshots existing client IDs, then runs at most KILL_WAVES (5) rounds that each kill at least one new connection via CLIENT KILL ID (memtier only), instead of CLIENT KILL TYPE normal for the whole run. That bounds run time that previously depended on reconnect timing vs. a 0.5 s kill grid (#680). The test also asserts at least one connection was dropped so the scenario cannot pass as a no-op.

_run now streams memtier stderr to a file, uses Popen/wait with explicit timeout handling, and reports elapsed time plus stderr tail on failure so CI can distinguish stalls from hangs.

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

…SK test

test_ask_retry_waits_for_reconnect ran CLIENT KILL TYPE normal on the
importing node every 0.5 s for as long as memtier ran, and memtier
reconnects 1 s after each drop (--reconnect-backoff-factor=1). The -ASK
retries waiting for that node, and with them both clients' pipelines,
completed only when a reconnect, its setup and the resends fit between two
kills. The run time had no bound: 4-17 s locally under ASan+UBSan, and
over the 60 s timeout on loaded CI runners (#680, again on PR #748 in
"UBSan OSS-CLUSTER API: TCP Plaintext").

memtier itself does not hang: every slow run kept making progress, and
with the killer bounded each run ends about 2 s after the last kill.

Kill only connections opened after the test started the killer (memtier's,
by CLIENT KILL ID), and stop after 5 rounds that dropped at least one.
Assert that some were dropped. Keep memtier's stderr in a file and print
its tail and the run time on failure or timeout, so a real hang would be
visible instead of a bare TimeoutExpired.

The test still guards #597: with redirect_target_conn() not accepting a
connection waiting on its reconnect timer, it fails every run with 45-86
requests ending on -ASK.

Fixes #680

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

Copy link
Copy Markdown

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

Thanks for this. The root-cause write-up is convincing, and running the #597 revert as a mutant answers the obvious worry that bounding the killer would stop the test from guarding that bug. Keeping memtier's stderr when it times out is a good change on its own merits. Two small questions:

  • The new assertGreater(killed[0], 0) only holds if memtier is still connected to the importing node when the first kill fires, 0.5 s in. Your timings (4.8-8.4 s) all come from the ASan+UBSan build. Did you check how long this run takes on the plain non-sanitizer jobs? If a fast build can finish all 2000 requests before the first wave, the guard against a silent no-op could become a new flake of its own. If that's possible, starting the first kill sooner (or waiting until memtier's connection appears in CLIENT LIST before starting the clock) might be safer.
  • Nitpicking: in _kill_clients, one CLIENT KILL ID that raises (say, memtier's connection closed between CLIENT LIST and the kill, so the server replies "No such client") skips the rest of that round's IDs. The next round picks them up, so I don't think it matters. Moving the try/except inside the for loop would make each round do what the docstring says, though.

Apart from that, the test-only fix looks good to me.

@fcostaoliveira

fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks. On the two points:

  • Can a fast non-sanitizer build finish before the first wave? No. Each client opens one connection per shard (memtier prints 1 threads x 2 conns/thread x 3 endpoints and 500 req/s/conn -> 3000 req/s aggregate), so the rate limit alone keeps a client's 1500 requests at about 1 s or more. Measured with kills disabled, the run takes about 2.0-2.1 s. The first kill fires at 0.5 s, well before that. With kills on, plain builds took 3.0-7.8 s and every run killed at least 3 memtier connections (12/12 runs). Under ASan+UBSan pinned to one CPU, runs took 3.3-6.3 s with 3-7 kills.
  • Could one CLIENT KILL ID raising "No such client" skip the rest of the round? It can't raise for a gone client. The filter form returns an integer: CLIENT KILL ID 999999 returns 0 on Redis 8.6, also with SKIPME yes. Only the legacy CLIENT KILL addr:port form returns ERR No such client. Only a connection-level error on the killer's own link would raise, and the next round picks those IDs up again.

#756 adds shared harness_client_ids / kill_memtier_clients helpers in tests/include.py for the same "kill only memtier's clients" pattern, with a _type="normal" filter. Once both are in, a small follow-up will switch this test to them, keeping the wave counter local.

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.

Flaky test: test_cluster_ask_asking::test_ask_retry_waits_for_reconnect times out (60 s) under ASAN

1 participant