Skip to content

Kill memtier's own connections, first thing, in the CLIENT KILL tests (#682) - #756

Merged
fcostaoliveira merged 4 commits into
masterfrom
fix/682-client-kill-flake
Oct 17, 2026
Merged

fcostaoliveira merged 4 commits into
masterfrom
fix/682-client-kill-flake

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

test_retry_on_error.py::test_dropped_transaction_requests_do_not_stall_requests_run sometimes fails on fast runners with no CLIENT KILL found a memtier connection (0 >= 1). On 2026-10-16 it failed CI on two open PRs at test_retry_on_error.py:1127: #752 ("Test Single Endpoint: TCP Plaintext") and #666 (coverage-ubuntu).

Review found the same flaw in three more --requests tests in test_reconnections.py. They sleep before their first kill, memtier is already done by then, and they pass without testing anything:

  • test_reconnect_on_connection_kill: 5000 requests and a 2 s sleep. Its only kill hit a harness connection, and its "reconnect" in stderr check matched the results path (.../test_reconnect_on_connection_kill/mb.json).
  • test_reconnect_unlimited_no_spurious_thread_restart: 5000 requests and a 1 s sleep. No memtier connection was killed, and it only checked that a message was absent.
  • test_reconnect_disabled_by_default: 10000 requests and a 1 s sleep. The kill hit an RLTest connection after memtier had exited.

Root cause

Each kill loop slept a fixed time before its first CLIENT KILL, and a --requests run can end inside that window. The kills also targeted every normal client (TYPE normal, or "any client not running CLIENT"), so kills of harness connections were counted as hits.

Fix (test only)

  • tests/include.py gets harness_client_ids, memtier_client_ids, wait_for_memtier_clients and kill_memtier_clients. Before memtier starts, they snapshot the IDs of the clients already on each server. They then poll CLIENT LIST every 1 ms and kill only the new clients, which are memtier's, and count only those.
  • _run_transaction_with_kills kills as soon as the first MULTI arrives (the INFO poll is now inside try/except), then every kill_interval, and kills and counts only memtier's clients. The --requests stall test stops after 10 waves (max_waves) and then has to finish the run. Before this, a cluster run was killed for the helper's whole 60 s window (62-64 s against a 90 s timeout). It now takes about 8 s. The test also asserts that a kill dropped at least one in-flight request (transaction-not-replayed).
  • The three test_reconnections.py tests now use _run_with_memtier_kills. Each wave waits for memtier's clients (the first connect, then each reconnect) and kills them straight away. Runs are longer: 20000 requests per client for the two reconnect tests, and 100000 for the disabled-by-default test. The assertions check what memtier itself reports, not the results path:
    • kills of memtier clients >= 1
    • attempting reconnection and Reconnection successful in memtier's stderr
    • Connection Errors >= 1 in mb.json
    • for the disabled-by-default case: --reconnect-on-error is not set and a non-zero exit

Other CLIENT KILL loops I checked. None of them ends before its kills:

  • --test-time runs that outlast their waves: the reconnect-interval test in test_reconnections.py, test_read_preference_failover.py, test_cluster_transaction.py, _replay_churn_run, test_dropped_replays_do_not_stall_client, test_prometheus.py F17 (--test-time=5, kills every 0.5 s), and test_json_output_integrity.py's run-count killer (--run-count=3 with --test-time=2, kills every 0.25 s).
  • Kills that wait for a condition first: test_test_time_stalled_server.py (kills once the server is stalled) and test_read_preference_mget.py (waits for replica MGET progress, inside a --test-time run).
  • test_cluster_ask_asking.py: kills every 0.5 s during a rate-limited run of about 3 s. Its timing is fixed separately in Bound the CLIENT KILL loop in test_ask_retry_waits_for_reconnect #758.
  • test_reconnect_cluster_mode_no_assertion (--test-time=10) now uses kill_memtier_clients too, so its kill_count no longer includes harness kills.

Test evidence (local, redis 8.6.0)

Each batch ran 8-10 RLTest copies in parallel. "pinned" means the whole RLTest tree (python, redis, memtier) was taskset to one core.

Stall test, before vs after. On this host the real run takes about 1 s, so the old code never failed it here (0/96 standalone, 0/8 cluster). A shorter run copies a fast CI runner:

  • At 3000 requests, the old helper failed 28/32 with no CLIENT KILL found.
  • The new helper failed 0/32 at 3000 requests and 0/32 at 1000.
  • Across the real-size runs since: 0/148 standalone and 0/11 cluster.

Changed reconnect tests, head:

test standalone (20 pinned + 10 unpinned) oss-cluster TLS
test_reconnect_on_connection_kill 0/30 failed 0/4 0/1
test_reconnect_unlimited_no_spurious_thread_restart 0/30 failed 0/4 0/1
test_reconnect_disabled_by_default 0/30 failed 0/4 0/1

Since the third commit (e1659f5: memtier clients are now TYPE normal only, CLIENT LIST and INFO poll failures are logged once, the dead limit parameter is gone), every changed test passes again: 3 standalone runs (2 plain, 1 TLS) and 1 cluster run each, with test_reconnect_cluster_mode_no_assertion passing 2/2 on cluster. test_transaction_requests_are_not_retried has 0 -ERR replies against 40 kills standalone and 61-76 on cluster, so the tighter errors <= killed bound holds.

The other helper users (test_transaction_requests_are_not_retried, test_transaction_drops_not_logged_without_retry, test_transaction_lost_multi_is_not_continued) pass 2/2 standalone and 1/1 cluster.

Mutants (each built from this tree):

mutant test base (origin/master test) head
reconnect never attempted (if (false && reconnect_on_error ...) in attempt_reconnect) test_reconnect_on_connection_kill passes, so it catches nothing: its only kill hits a harness connection, and memtier's stderr has no reconnect line (locally its unconditional debugPrintMemtierOnError call then raises on a missing redis log, which is a quirk of my runner) fails 6/6: exit 1, "memtier logged no reconnection attempt"
same test_reconnect_unlimited_no_spurious_thread_restart passes 3/3 (catches nothing) fails 3/3
reconnect_on_error on by default test_reconnect_disabled_by_default passes 3/3 (catches nothing) fails 3/3: memtier exited 0 and did not end the thread
abandon_requests() removed from disconnect() (the #615 accounting) stall test — fails 3/3 standalone, 2/2 cluster with the 10-wave cap ("client stopped sending", exit 1)
#391 guard removed (the m_reconnecting early return) test_reconnect_unlimited_no_spurious_thread_restart passes passes, plain and TLS. CLIENT KILL does not produce the duplicate error callbacks this guard is for, on either version. The docstring now says so: the test covers the unlimited-reconnect path, not the #391 storm.

Fourth commit (e67a529): TSan cluster flake and password envs

  • TSan failure: "TSAN OSS-CLUSTER API: TCP Plaintext" failed the new drop assertion: 32 memtier clients killed, 0 failed-keys rows. The cause was the 10-wave cap. In a slow build, its waves (0.3 s apart) landed while the connections were idle or still reconnecting (1 s delay).
  • Fix: before each wave, _run_transaction_with_kills now waits until memtier has sent a MULTI since the previous wave. With until_dropped, it keeps killing until a transaction-not-replayed row appears in --failed-keys-file, which memtier flushes per row. The safety cap is max_waves=50 plus the helper's 60 s window. memtier must still complete the run once the kills stop.
  • Measured with a local TSan build (--enable-thread-sanitizer, under setarch -R):
    • oss-cluster: 0/16 failed, 8 of them pinned two runs per core.
    • standalone: 0/4 failed.
    • The old version did not fail locally (0/8). I did not reproduce the CI timing.
  • Plain build, after the change:
    • stall test: 0/6 failed standalone (pinned) and 0/2 on cluster. Standalone needs one wave.
    • The abandon_requests mutant is still caught: 3/3 standalone and 2/2 cluster.
    • The other helper tests pass.
  • Password envs: the test_reconnections.py kill tests now pass --authenticate when the env has a password, as test_cluster_ask_asking does. Under --oss_password, the previous head's test_reconnect_cluster_mode_no_assertion killed 0 memtier clients and failed. It now passes (48 kills), and so do the other three tests, standalone and on cluster.

Affected versions

Test suite and CI only; release binaries are not affected. The stall test came in with 013cb85 (#615), and git tag --contains 013cb85 is empty, so no release tag has it (latest is 2.5.2). The three test_reconnections.py tests have been vacuous on fast runners since they were added.

Fixes #682. This also covers item 2 of #740 (the same failure seen on the coverage job).

🤖 Generated with Claude Code


Note

Low Risk
Test harness and CI only; no production or memtier binary behavior changes.

Overview
Fixes flaky and sometimes vacuous CLIENT KILL integration tests by targeting only memtier’s Redis clients and killing as soon as workload is visible, instead of sleeping then blasting TYPE normal.

tests/include.py adds shared helpers: snapshot harness client IDs before memtier starts (harness_client_ids), poll for new normal clients (memtier_client_ids / wait_for_memtier_clients), and CLIENT KILL ID … SKIPME yes only those (kill_memtier_clients).

tests/test_reconnections.py replaces background killer threads and fixed delays with _run_with_memtier_kills (wait-for-client then kill per wave), optional --authenticate via _add_auth_args, longer --requests runs, and assertions on memtier stderr (attempting reconnection, Reconnection successful) and mb.json Connection Errors. Cluster regression test counts kills via the new helpers.

tests/test_retry_on_error.py updates _run_transaction_with_kills to use the same memtier-only kills, trigger the first wave when MULTI appears (not after kill_interval), and adds max_waves / until_dropped so the stall test stops after a real drop instead of killing for ~60s on cluster.

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

@fcostaoliveira
fcostaoliveira force-pushed the fix/682-client-kill-flake branch from e017a6c to 85669f4 Compare October 17, 2026 00:25
@fcostaoliveira fcostaoliveira changed the title Kill on the first transaction in the --transaction kill-loop tests (#682) Kill memtier's own connections, first thing, in the CLIENT KILL tests (#682) Oct 17, 2026
@github-actions

Copy link
Copy Markdown

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

Thanks for this. Starting the first kill on the first MULTI is the right fix for #682, and the new transaction-not-replayed assertion means the test fails loudly now instead of passing without checking anything. A few comments:

  • The title and description only cover the first commit. The second commit rewrites three tests in test_reconnections.py, adds shared kill helpers to include.py, and changes what _run_transaction_with_kills counts as a kill. That's a bigger change than "kill on the first transaction". I think it would be a good idea to either update the title/body to cover it, or split the reconnect-test rework into its own PR. The before/after evidence in the body is also only for the transaction test. Did you run the three reconnect tests across the matrix too (cluster, TLS)?

  • killed now counts only memtier's clients. Before, CLIENT KILL TYPE normal also killed and counted the harness connections. That makes errors <= killed in test_transaction_requests_are_not_retried a stricter bound than it was. It's more correct, but did you check that bound on cluster runs? Some of the slack it used to have came from harness kills.

  • In test_reconnect_disabled_by_default (and the first wave of the other two), memtier's connection can now be killed right after accept, before any request. In cluster mode that's the seed connection, mid-CLUSTER SLOTS. Does Connection Errors in mb.json always get bumped on that path? I think Report connection errors and Ctrl+C of clients that never connected #707 covers it, but I may be wrong. If it doesn't, these become a new flake source rather than fixing one.

  • Just checking: harness_client_ids assumes no harness connection opens after the snapshot. That holds today because kill_loop runs on the calling thread and the pool reuses one connection. A short note in the docstring would keep someone from later moving the kills to a background thread with a shared pool, where a new pooled connection would get killed as if it were memtier's.

  • Nitpicking: once the threaded killer is gone, is threading still used in test_reconnections.py?

The core fix looks solid to me. I'd mainly want the scope/description sorted out and the cluster runs confirmed before this merges.

@fcostaoliveira
fcostaoliveira force-pushed the fix/682-client-kill-flake branch from 85669f4 to e1659f5 Compare October 17, 2026 01:00
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Replies point by point to the review of 00:26:54Z:

  1. Scope: I updated the title and body. They now cover all three commits and the rework of the three test_reconnections.py tests, with the matrix evidence: each reconnect test passed 30/30 standalone (20 of them pinned to one core), 4/4 on oss-cluster and on TLS. They also have the mutant results, including the one these tests don't catch (attempt_reconnect kills the benchmark thread on duplicate connection errors while a reconnect is already pending #391).
  2. errors <= killed on cluster: it holds. test_transaction_requests_are_not_retried sees 0 -ERR replies against 61-76 memtier kills on oss-cluster, and 0 against 40 standalone. The bound never needed the slack the harness kills used to give it.
  3. Connection Errors after an early kill: yes, it is counted. Every early-kill path (Connection error, Connection dropped, the cluster seed Connection failed) goes through shard_connection::attempt_reconnect(), and that calls update_connection_error() unconditionally before it checks --reconnect-on-error. test_reconnect_disabled_by_default asserts Connection Errors >= 1 and passed 3/3 on oss-cluster, where the seed connection is killed mid-CLUSTER SLOTS.
  4. The harness_client_ids assumption: it is now in the docstring (e1659f5). The kills run on the calling thread, which reuses the one pooled connection per server. A second polling thread on the same pool could open a new connection, which would then be taken for memtier's and killed. The helpers also count only TYPE normal clients now, so a replica link that connects later is never killed.
  5. threading: still used elsewhere in test_reconnections.py (3 uses), so the import stays.

fcostaoliveira and others added 4 commits October 17, 2026 02:37
test_dropped_transaction_requests_do_not_stall_requests_run failed on
fast runners with "no CLIENT KILL found a memtier connection": the
kill loop in _run_transaction_with_kills slept kill_interval (0.3s)
before its first CLIENT KILL, and a 30000-request run can end inside
that window. Nothing was killed, so the test checked nothing.

The loop now polls INFO commandstats until the first MULTI arrives and
kills straight away, then every kill_interval. A run can no longer end
before the first wave, however fast the runner. The test also asserts
that a kill dropped at least one in-flight transaction request
(transaction-not-replayed), so it fails loudly if the scenario it
guards is ever not reached.

The other callers of the helper use --test-time and keep working; their
first wave just comes earlier.

Fixes #682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… tests

Three --requests tests in test_reconnections.py slept before their first
kill, and memtier finished well inside that sleep, so they passed without
testing anything:
- test_reconnect_on_connection_kill (2s sleep, 5000 requests): its only
  kill hit a harness connection, and its "reconnect" check matched the
  results path in stderr.
- test_reconnect_unlimited_no_spurious_thread_restart (1s sleep): no
  memtier connection was killed; it only checked a message was absent.
- test_reconnect_disabled_by_default (1s sleep): the kill hit an RLTest
  connection after memtier had exited.

include.py gets helpers that snapshot the harness's client IDs before
memtier starts, then wait for memtier's clients and kill only those. The
tests kill on each connect and reconnect, have longer runs, and assert
on what memtier itself reports: "attempting reconnection" and
"Reconnection successful" in its stderr, Connection Errors in mb.json,
and for the disabled case "--reconnect-on-error is not set" and a
non-zero exit.

_run_transaction_with_kills uses the same helpers, so its kill count no
longer includes harness clients. Its INFO poll is guarded, and the
--requests stall test stops killing after 10 waves. Before that cap, a
cluster run was killed for the whole 60s window, close to the 90s
timeout, and memtier now has to finish the run once the kills stop.

Fixes #682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Count only TYPE normal clients as memtier's, so a replica link that
  connects after the snapshot is never killed.
- Document that harness_client_ids assumes no harness connection opens
  after the snapshot (kills on the calling thread, one pooled connection).
- Log a CLIENT LIST failure once instead of silently polling for 30s, and
  log only the first failed INFO poll in _run_transaction_with_kills.
- Drop kill_memtier_clients' unused limit parameter.
- test_reconnect_cluster_mode_no_assertion kills and counts only
  memtier's clients too.
- test_reconnect_unlimited_no_spurious_thread_restart: say plainly that
  CLIENT KILL does not reproduce the #391 duplicate-callback storm; the
  test covers the unlimited-reconnect path, not that guard.

Refs #682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TSAN OSS-CLUSTER failed test_dropped_transaction_requests_do_not_stall_
requests_run with "no in-flight transaction request was dropped on a
kill": 32 memtier clients killed, 0 failed-keys rows. With a slow build,
the 10 capped waves, 0.3s apart, landed while the connections were idle
or still reconnecting (1s delay), so none of them had a request in
flight.

_run_transaction_with_kills now waits, before each wave, until memtier
has sent a MULTI since the previous wave, so a wave never lands while
every connection is reconnecting. With until_dropped, the waves keep
going until a transaction-not-replayed row shows up in the failed-keys
file, which memtier flushes per row. The stall test uses until_dropped
with max_waves=50 (and the helper's 60s window) as the safety cap, and
memtier must then still complete the run.

The test_reconnections.py kill tests now pass --authenticate when the
env has a password (e.g. --oss_password), as test_cluster_ask_asking
does. Without it, test_reconnect_cluster_mode_no_assertion killed 0
memtier clients: it had only passed because CLIENT KILL TYPE normal
also killed the harness's own connections.

Refs #682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/682-client-kill-flake branch from e1659f5 to e67a529 Compare October 17, 2026 01:37
@fcostaoliveira
fcostaoliveira merged commit 0ea5c6f into master Oct 17, 2026
129 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

1 participant