Skip to content

Don't report a worker that already ended as a --connection-stage-timeout abort - #891

Merged
fcostaoliveira merged 2 commits into
masterfrom
claude/cli-fuzz-supervisor-race
Oct 25, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
claude/cli-fuzz-supervisor-race

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #890.

Problem

run_benchmark() sleeps one second, asks the connection-stage supervisor whether to abort, and only then counts the workers still running. Suppose a worker fails on its own during that sleep, before any connection reaches steady state, and the timeout has expired by the next poll. The run is then also reported as an abort: memtier prints both the worker failure and aborting after N seconds of connection-stage failures, and exits 2 instead of 1.

That made case #8 of test_cli_fuzz_phase1.py (--data-size-range 1-9999999999) flaky on TSan. It failed this way in #886's CI:

  • Redis rejects the oversized SET with -ERR Protocol error, which counts as a connection rejection.
  • About 4 s later Redis resets the connection.
  • The 6 s budget, counted in whole seconds from the run start, then expires at the next poll.

Change

The supervisor is checked only while at least one worker is still running. When none is, the loop sees no active thread and the run reports how its workers ended.

One more case changes: a worker that ends cleanly without ever reaching steady state, e.g. a --requests run whose only replies were connection rejections, now exits 0 where it used to exit 2. That happens because rejection replies already count as processed requests, which is a separate, existing rule (#686/#788). Tracked in #894.

Results

Case #8's own arguments, against a local redis-server 8.6.0. The counts are runs that exited 2:

Build Conditions Timeout master this PR
TSan idle 6 s 5 of 28 0 of 32
plain 1 CPU shared with 2 busy loops 3 s 10 of 10 1 of 10*
plain idle 1 s 4 of 4 0 of 4

* A correct abort, not this bug: no worker failure was printed. Redis reset the connection about 2.9 s in, right at the 3 s budget, so the worker was still in setup when the timeout fired.

Tests

  • New test: tests/test_connection_stage_worker_ended.py runs --connection-stage-timeout=1 against a scripted peer that closes the connection without replying 0.2 s after the first command. This makes the race deterministic. The test fails 5/5 on master (plain and TSan), and passes 10/10 plain and 5/5 TSan with this PR.
  • Second case: test_worker_still_in_setup_is_supervisor_abort uses 4 threads. The peer closes 3 connections and never answers the 4th, so the run must still abort with exit 2 at the timeout. A variant that skips the supervisor unless all workers are running hangs here, and passed every other test.
  • Phase 1 file: the full test_cli_fuzz_phase1.py file plus the new test passed 8/8 in each of 3 runs at 587f123, before the second case was added, on a TSan build with the workflow's settings, with no TSan reports.
  • Related tests: 19 supervisor-related files, standalone, give 251 passed and 0 failed. make check passes 18/18.
  • Mutants:
    • Checking the supervisor unconditionally fails only the new test, so it alone guards this.
    • Inverting the running check fails the new test and 6 of the 7 phase 1 supervisor cases.
    • Requiring all workers running instead of any hangs the second case until it is killed.
  • Remaining window: tens of microseconds, the worker's exit path (38-71 µs measured). In that window the worker really was still in setup when the supervisor decided.

Affected versions

The check order dates from 2e8869e (#431), in 2.4.0 through 2.5.2. The exit-1 worker-failure path it collides with came in with 7a6394e (#546), which no release tag contains. So the visible bug is on master only.

🤖 Generated with Claude Code


Note

Medium Risk
Touches main benchmark loop exit semantics around connection-stage supervision; behavior change is narrow but affects process exit codes and when runs are aborted vs. reported as worker failures.

Overview
Fixes a race where --connection-stage-timeout could label a run as a supervisor abort (exit 2) even when every worker had already failed on its own (exit 1).

After the main loop’s one-second sleep, run_benchmark() now checks whether any worker thread is still running before calling connection_stage_should_abort(). If all workers have finished, the supervisor is skipped so the process reports the workers’ natural outcome instead of printing aborting after N seconds of connection-stage failures. When at least one worker is still stuck in connection setup, the timeout path is unchanged.

Adds tests/test_connection_stage_worker_ended.py: a scripted TCP peer that closes early vs. leaves a worker hanging, asserting exit 1 without the timeout message in the first case and exit 2 with the message when one worker remains in setup.

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

…out abort

run_benchmark() sleeps one second, asks the connection-stage supervisor
whether to abort, and only then counts the workers still running. A
worker that failed on its own during that sleep, before any connection
reached steady state, was therefore also reported as an abort when the
timeout had expired by that poll. memtier printed both the worker
failure and "aborting after N seconds of connection-stage failures" and
exited 2 instead of 1.

This made test_cli_fuzz_phase1.py's #8 case (--data-size-range
1-9999999999) flaky on TSAN: Redis rejects the oversized SET with -ERR
Protocol error and resets the connection about 4 s later, and the
supervisor's 6 s budget, measured in whole seconds from the run start,
expired at the next poll. Locally 3 of 8 TSAN runs exited 2, and 10 of
10 plain runs did when memtier shared one CPU with two busy loops.

Skip the supervisor when no worker is running. The loop then sees no
active thread and the run reports how its workers ended.

test_connection_stage_worker_ended.py runs memtier with
--connection-stage-timeout=1 against a scripted peer that closes the
connection without replying 0.2 s after the first command, so the
worker fails before the first poll, which is the one where the timeout
has expired. It exits 2 without this fix and 1 with it.

Fixes #890

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The supervisor is skipped only when no worker is running. Nothing checked
the "no" part: test_connection_stage_worker_ended.py ran one thread, where
"any worker running" and "every worker running" are the same condition.
With the latter, a run with one failed worker never polls the supervisor
again, and a worker stuck in setup keeps it waiting forever, which is the
hang that --connection-stage-timeout exists to bound.

Add a case with four threads: the scripted peer closes three connections
0.2 s after their first command and never answers the fourth. With
--connection-stage-timeout=1 memtier must exit 2 with the abort hint, in
well under 15 s. The subprocess timeout is 30 s, so a hang fails the test
instead of stalling the suite. The case takes about 1.5 s; with "every
worker running" memtier is still running at 30 s.

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

Copy link
Copy Markdown
Collaborator Author

Owner summary at 3e81db5: all 7 lenses approve (SEM, OUT, TEST, BUILD, LIFE, INTER, MAINT).

  • CI: 144 jobs succeeded, 6 were skipped by trigger or label, and none failed. Bugbot found no issues, and there are no review threads.
  • New file: test_connection_stage_worker_ended.py passed both cases in all 6 non-cluster cells, including TSan, where the stuck-worker case aborted in 1.5 s against its 15 s bound. It skips in the cluster and TLS cells by design.
  • Phase 1: test_cli_fuzz_phase1.py gave 104 pass, 57 skip and 0 fail, the same split as master. Case Incorrect throughput in final table #8 passed in all 3 TSan cells.
  • Mutants:
    • Checking the supervisor unconditionally fails the first case.
    • Inverting the running check fails the first case and 6 of 7 phase 1 cases.
    • Requiring all workers running instead of any hangs the second case until it is killed.
  • Remaining window: tens of microseconds, the worker's exit path (38-71 µs measured). In that window the worker was still in setup when the supervisor decided, so exit 2 is right. A post-join decision would close it, but it would move the abort message to teardown and can't be tested without a delay hook, so I left it out.
  • Follow-up: A run whose only replies were connection rejections (-ERR Protocol error, max number of clients, -DENIED protected mode) exits 0 and reports them as throughput #894. A run whose only replies were connection rejections exits 0. That is an existing rule, not caused by this PR.

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira merged commit bc1708a into master Oct 25, 2026
151 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.

A worker that fails just before a --connection-stage-timeout poll is also reported as an abort (exit 2 instead of 1)

1 participant