Skip to content

Stop the --run-count series on Ctrl+C - #698

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix-690-interrupt-run-count
Oct 16, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix-690-interrupt-run-count

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Behaviour decision (for maintainers to push back on): Ctrl+C now ends the whole --run-count series. The run that was interrupted is kept and marked Interrupted: true. No later run starts.

  • Keys stay the same. The section keys follow --run-count: BEST / WORST / AGGREGATED AVERAGE RESULTS (<run_count> runs). This is the key that in-repo consumers build from the run count (tests/test_cluster_redirect_stats.py:145, tests/tests_oss_simple_flow.py:489, tests/test_hdr_histogram.py:220).
  • Contents cover only the runs that happened. BEST, WORST and the aggregate are built from those runs. With --print-all-runs, the RUN #k RESULTS sections are also cut back to those runs.
  • The completed-run count is reported:
    • always as "Runs completed" in the JSON run information section. The count includes the interrupted run;
    • when the series was cut short, as a text line 1 Runs completed (of 3, interrupted);
    • on stderr as Interrupted by user (Ctrl+C), skipping the remaining runs (k of N done).
  • Each run keeps its own Interrupted flag. RUN #k is Interrupted: true only for the run that actually saw the signal. A run that completed cleanly before the cut stays false, whatever --run-count is, so a consumer that drops interrupted runs keeps complete data. BEST and WORST are copies of a run, so they carry that run's flag.
  • The AGGREGATED section is marked Interrupted when any run was interrupted, or when the series was cut short. That includes a Ctrl+C that lands in the settle pause between runs, which no single run sees. A cut series can be detected from Runs completed being lower than run_count in configuration, and from the text line.
  • Ctrl+C during the last run skips nothing. Only that run and the aggregate are Interrupted.

Also affected, besides Ctrl+C: aggregate_average() now carries over any run's Interrupted flag. So when a --connection-stage-timeout abort ends run 1 of a --run-count series (the abort calls interrupt(), and the next run resets the abort flag and continues), AGGREGATED is now marked Interrupted: "true" too. This is intended: the average includes a truncated run. Only that run and the aggregate are marked.

Problem

With --run-count=N, Ctrl+C stopped only the current run. memtier then started every remaining run anyway. Each one sent about 1 s of full load, was interrupted, and was counted in BEST/WORST/AGGREGATED. The aggregate said Interrupted: false.

Root cause

  • g_interrupted is set once by sigint_handler() and is never cleared. The run loop in main() never checks it.
  • In each later run, the supervisor loop in run_benchmark() calls sleep(1) before it checks g_interrupted, so each extra run sends a full second of load. Together with the 1 s settle pause between runs, that is about 2 s per remaining run.
  • run_stats::aggregate_average() did not carry m_interrupted over from its runs. merge() already does.

Fix

  • main(): before starting run 2 and every later run, check g_interrupted both before and after the settle sleep(1). The signal can arrive during the pause; if it goes to another thread, sleep() is not cut short, and the second check still catches it. Run 1 always runs, so all_stats is never empty.
  • Report Runs completed and the stderr note described above.
  • When the series was cut short (all_stats.size() < cfg.run_count), mark the aggregate Interrupted. Per-run flags are left alone.
  • aggregate_average(): the average is marked interrupted if any of its runs was.

Tests

Pass/fail counts are from local runs.

  • test_interrupt_stops_run_count (new). Sends SIGINT 1.5 s into --run-count=3 --test-time=30. It checks:

    • exit code 0, exactly one Interrupted by user line, and no [RUN #2;
    • the stderr skip note;
    • Runs completed == 1;
    • BEST, WORST and AGGREGATED AVERAGE RESULTS (3 runs) are all Interrupted: "true";
    • the aggregate's Ops/sec equals BEST's within 1%;
    • exit within 3.5 s of the SIGINT, as a loose sanity bound. Master takes at least 4 s (measured 4.0 s); the fix takes at most about 1 s.

    Results: origin/master 3/3 FAIL; this branch 5/5 PASS, plus PASS on oss-cluster with 3 shards.

  • test_interrupt_between_runs_stops_run_count (new). Runs --run-count=3 --test-time=1. The test waits until run 1's last progress line ([RUN #1 <any>% ... 0 threads; on TSAN builds progress goes past 100%, which is what broke the first CI run), waits another 0.4 s so the SIGINT lands inside the settle pause, then sends it. It checks: no [RUN #2, Runs completed == 1, RUN pcre required for build #1 / BEST / WORST Interrupted: "false" (run 1 completed cleanly), and the aggregate Interrupted: "true".

    Binary Result
    origin/master 3/3 FAIL
    this branch 5/5 PASS at this head (10/10 at the previous head, before the per-run flag change), plus PASS on oss-cluster
    mutant without the g_interrupted check after the pause 10/10 FAIL (measured at the previous head; the loop is unchanged since)
    TSAN build (--enable-thread-sanitizer, setarch -R, CI suppressions), this branch 10/10 PASS standalone, plus PASS on oss-cluster
    TSAN build, mutant without the check after the pause 5/5 FAIL
    mutant without if (series_cut) average.set_interrupted(true); 3/3 FAIL
  • test_interrupt_last_run_marks_aggregate (new). Runs --run-count=2 --test-time=2 and sends SIGINT 0.5 s after [RUN #2 appears. It checks: one Interrupted by user line, no skip note, Runs completed == 2, RUN pcre required for build #1 Interrupted: "false", RUN CentOS release 6.4 (Final) installation torture #2 and AGGREGATED AVERAGE RESULTS (2 runs) Interrupted: "true".

    Binary Result
    origin/master 3/3 FAIL
    this branch 5/5 PASS, plus PASS on oss-cluster
    mutant without if (i->m_interrupted) m_interrupted = true; in aggregate_average() 5/5 FAIL

    This is the only test that catches that mutant. In the series-cut tests, the cut-series marking also sets the aggregate's flag, so they pass on it.

  • All three interrupt tests run with --print-all-runs and check that RUN #1 RESULTS and BEST/WORST carry the same flag.

  • F27 in tests/test_prometheus.py (from Export every operation in memtier_latency_seconds (fixes #637) #665). It relied on run 2 starting after Ctrl+C, so that it could scrape run 1's run-end snapshot in the gap before run 2. That gap no longer exists.

    • How it works now: the test sends the results (--out-file) to a FIFO shrunk to one page (F_SETPIPE_SZ 4096) and does not read it. memtier publishes the run-end snapshot and then blocks writing the results. Nothing is written to the out file before the run loop ends, so the exporter stays up.
    • The test scrapes until it sees run 1 with 0 threads, asserts _count == ops_total, then drains the FIFO and checks exit code 0.
    • It skips if the pipe cannot be shrunk to 4 KiB (no F_SETPIPE_SZ, or 64 KiB pages).

    Results: this branch 8/8 PASS, plus PASS on oss-cluster. The mutant with prom_publish_run_end using prom_drain_latency(cfg, threads, false) fails 8/8 (for example _count 1522688 != ops_total 1749472).

  • Existing tests: test_interrupt_signal_handling, test_print_all_runs and test_aggregated_average_totals_histogram still pass.

Manual repro: timeout -s INT 2 memtier_benchmark --test-time=30 --run-count=3 --print-all-runs ...

  • Before: 3 Interrupted by user lines (2.0 s, 1.0 s, 1.0 s), 6.1 s wall time, and an aggregate with Interrupted: false.
  • After: 1 line and 2.0 s wall time. The sections are RUN #1, BEST, WORST and AGGREGATED AVERAGE RESULTS (3 runs), all Interrupted: true (run 1 saw the signal) with the same Ops/sec, and Runs completed: 1.

Fixes #690

Affected versions

2.3.0 through 2.5.2 (latest) and master.

  • Introduced by: aa9edb8, "Signal Handling with Graceful Shutdown with metrics (Signal Handling with Graceful Shutdown with metrics #325)". It added sigint_handler / g_interrupted and the check inside run_benchmark(), but not in the --run-count loop. Before that commit, SIGINT killed the process. The first tag that contains it is 2.3.0.
  • Confirmed by running: master and 2.5.2 (f3ff179), in the issue. Also origin/master 6eedafb, 577e799 and 1d13ff5, in this PR. The branch is rebased on 8f5fa34.
  • Derived from history: 2.3.0 through 2.5.1.

Found during the review of PR #665.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

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

Thanks for this. I went through the diff and the description, and I have a few comments below.

On the behaviour decision you asked about: I think ending the whole series on Ctrl+C is what a user expects, so I wouldn't push back on it. Keeping the AGGREGATED AVERAGE RESULTS (<run_count> runs) key stable, and adding Runs completed to the output, also seems like the right call. It's the same kind of reasoning as PR#212, where the less-breaking fix won over the "more correct" one. The text-output change only shows up when a series is cut short, which keeps the blast radius small. The new tests are pinned to master failures and to the mutants, which is the bar PR#364 set.

  • aggregate_average() now carries over m_interrupted from any run. As far as I can tell, Ctrl+C isn't the only thing that sets it. The connection-stage abort path also calls m_cg->interrupt() (memtier_benchmark.cpp:3706), and that ends up in set_interrupted(true) (client.cpp:1592). The series then goes on to run 2, because connection_stage_supervisor_reset() clears the abort flag. So with --run-count=3, a connection-stage abort in run 1 will now mark AGGREGATED as Interrupted: "true" even though nobody pressed Ctrl+C. That's probably the right outcome, since the average does include a truncated run. Is it intended, though? If so, it may be worth a line in the PR description, because it changes the output in a case that isn't Ctrl+C, and no test covers it.
  • In test_interrupt_stops_run_count, the elapsed < 3.5 bound leaves about 2.5 s of headroom over the ~1 s you expect. You already hit TSAN slowness in the between-runs test. Have you seen how long the SIGINT-to-exit step takes on the TSAN cells? A thread join that's slow under TSAN could make this test flaky.
  • Nitpicking: the stderr note says "Interrupted by user (Ctrl+C), skipping the remaining runs". When the signal lands in the settle pause, no run was interrupted, so the wording is a little off. Not worth changing unless you're already touching that line.

The core fix looks solid. I'd mainly like the first point confirmed as intended before this merges.

@fcostaoliveira
fcostaoliveira force-pushed the fix-690-interrupt-run-count branch from 0c47a31 to 0be4a85 Compare October 16, 2026 10:27
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Taking the points in order (pushed in 10846ec):

  1. JSON key. Agreed, and changed. The aggregate key stays AGGREGATED AVERAGE RESULTS (<run_count> runs), which is how tests/test_cluster_redirect_stats.py, tests/tests_oss_simple_flow.py and tests/test_hdr_histogram.py build it. The number of runs it actually holds is a new "Runs completed" field in the JSON run information section. When the series was cut short there is also a text line, 1 Runs completed (of 3, interrupted). BEST, WORST and the aggregate are now marked Interrupted: true whenever fewer runs completed than requested, including when Ctrl+C lands in the settle pause between runs and no single run sees it. A new test covers that case.
  2. Timing check. It is only a sanity bound. With the fix, memtier exits after at most the supervisor's 1 s tick; in local runs it is well under 1 s. Master needs at least 4 s, because the two extra runs each add a 1 s pause plus 1 s of load (measured 4.0 s). The [RUN #2 / Runs completed / Interrupted assertions are what pin the fix, so 3.5 s leaves more than 2.5 s of headroom for slow runners. I reworded the test comment to say it is a sanity bound.
  3. Comment. You're right. If the signal goes to another thread, sleep(1) runs to completion. The comment now says only that the signal can arrive during the pause, which is why g_interrupted is checked both before and after it.
  4. --out-file before the publish. Yes. outfile is opened before the run loop, but the first write to it is the "run information" block after the loop, after the last prom_publish_run_end. F27 now also skips when F_SETPIPE_SZ can't shrink the pipe to 4 KiB (for example on 64 KiB page kernels), since about 32 KB of results might not block a bigger pipe.

@fcostaoliveira
fcostaoliveira force-pushed the fix-690-interrupt-run-count branch from 10846ec to 0373d28 Compare October 16, 2026 10:41
fcostaoliveira and others added 4 commits October 16, 2026 11:48
With --run-count=N, Ctrl+C stopped only the current run. g_interrupted
stays set and the run loop in main() never looked at it, so every
remaining run started anyway: a 1 s settle pause, then 1 s of full load
(the supervisor sleeps before it checks g_interrupted), then another
"Interrupted by user". Those fragments were counted in BEST/WORST and in
"AGGREGATED AVERAGE RESULTS (N runs)", where N was cfg.run_count.

The loop now stops before starting another run once g_interrupted is
set, checked before and after the settle pause. The run that was
interrupted is kept (it is marked Interrupted), and run 1 always runs so
the summary is never empty. A stderr line says how many runs were done.
The section layout still follows --run-count; the "(N runs)" header uses
the runs that happened, and aggregate_average() marks the average
Interrupted if any of its runs was, like merge() already does.

Test F27 relied on run 2 starting after Ctrl+C to scrape run 1's
run-end snapshot in the gap. It now writes the results to a one-page
FIFO that it does not read, so memtier blocks after publishing the
run-end snapshot and the exporter stays up until the test drains it.
It still fails if the run-end publish skips the live histograms.

Fixes #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review of the #690 fix:

- The aggregate section stays "AGGREGATED AVERAGE RESULTS (<run_count>
  runs)", the key in-repo consumers build from --run-count. The number
  of runs it holds is now reported as "Runs completed" in the JSON
  "run information" section, and as a text line when the series was
  cut short.
- A Ctrl+C that lands in the settle pause between runs stops the series
  without interrupting any run. BEST, WORST and the aggregate are now
  marked Interrupted whenever fewer runs completed than requested.
- Add a test that interrupts in the settle pause after run 1. It fails
  if the g_interrupted check after the pause is dropped. The run-count
  tests also check "Runs completed" and that the one-run average equals
  that run.
- F27 skips when the FIFO cannot be shrunk to 4 KiB (64 KiB pages).
- Reword the loop comment: SIGINT can be delivered to another thread,
  in which case sleep() is not cut short.

Refs #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When Ctrl+C cuts the --run-count series short, mark every completed
run Interrupted before any section is printed, instead of only BEST and
WORST after the per-run sections. With --print-all-runs, RUN #k now
agrees with BEST/WORST for the same run. The aggregate picks the flag
up through aggregate_average().

Add a test for Ctrl+C during the last run (--run-count=2, all runs
done, nothing skipped). There the aggregate's Interrupted flag comes
only from aggregate_average() carrying it over from the interrupted
run, which no other test covered. The run-count tests now also run
with --print-all-runs and check RUN #1's flag.

Refs #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Marking every run of a cut series Interrupted made a run's flag depend
on --run-count: a run 1 that completed cleanly before a Ctrl+C in run 2
was "true" with --run-count=3 but "false" with --run-count=2, and a
consumer that drops interrupted runs would lose complete data.

Each RUN #k now keeps its own flag, true only for the run that saw the
signal. BEST and WORST are runs, so they carry that run's flag. Only
the AGGREGATED section is marked when the series was cut short (or, via
aggregate_average(), when any run was interrupted). A cut series is
visible from "Runs completed" < run_count and the text line.

The settle-pause test now expects RUN #1/BEST/WORST "false" and AGG
"true". F27: comment why run_end is re-checked after assertTrue.

Refs #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix-690-interrupt-run-count branch from 0373d28 to 5cf0496 Compare October 16, 2026 10:52
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. On the question from the 10:42 edit: agreed, and changed in 5cf0496.

  • Per-run flags. Each RUN #k now keeps its own flag. It is Interrupted: true only for the run that actually saw the signal. So a run that completed its full --test-time before a Ctrl+C in the settle pause stays false, whatever --run-count is, and filtering out interrupted runs no longer drops complete data. BEST and WORST are copies of a run, so they carry that run's flag and match its RUN #k section.
  • Aggregate. Only AGGREGATED AVERAGE RESULTS is marked Interrupted when the series was cut short. It is also marked when any run was interrupted, through aggregate_average().
  • Detecting a cut series. A consumer can see it from run information → Runs completed (which includes the interrupted run) being lower than configuration → run_count, or from the Runs completed (of N, interrupted) text line.
  • Tests. The settle-pause test now expects RUN pcre required for build #1 / BEST / WORST to be "false" and AGG to be "true". The last-run test still catches dropping the propagation in aggregate_average() (3/3 FAIL).
  • F27 nit. Done. There is now a comment on the if run_end is not None: saying env.assertTrue records a failure but does not raise.

@fcostaoliveira

fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Re the automated review as edited at 10:54:

  • (a) Out-of-date descriptions: the PR body describes the current behaviour. The squash commit message will be written from the final head (each run keeps its own flag; only the aggregate is marked when the series is cut short), not from the intermediate commit messages.
  • (b) Text note far from the AGGREGATED heading: left as is on purpose. The heading text matches the JSON key, which in-repo tests and probably external parsers build from the run count. In text output, the Runs completed (of N, interrupted) line sits next to the other run information. JSON consumers have Interrupted and Runs completed.
  • (c) Settle-pause test timing: the concern is valid. Correction: an earlier version of this comment said the test passed in every CI cell. It does not: at 10846ec, test_interrupt_between_runs_stops_run_count failed in both TSAN Plaintext cells. All 3 runs completed (Runs completed: 3), so the SIGINT did not land in the settle pause under TSAN's slowdown. This is being fixed in the test before merge.
  • (d) The 1031 fallback in F27: noted. It's cosmetic, so I'll leave the code unchanged in this PR.

test_interrupt_between_runs_stops_run_count waited for
"[RUN #1 100% ... 0 threads" before sending SIGINT. On a slow build
(the TSAN CI cells) the progress of a --test-time run goes past 100%
("[RUN #1 104%, 1 secs]  0 threads"), so the trigger never matched,
memtier ran all three runs, and the SIGINT went to an exited process.
memtier itself handled the signal fine: under TSAN the 0-threads line
comes about 1.002 s before "[RUN #2", so the signal sent 0.4 s after it
lands in the settle pause as intended.

Match any percentage, and fail clearly if the trigger has not fired
before memtier exits.

Refs #690

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

Copy link
Copy Markdown
Collaborator Author

Re the automated review as edited at 11:10:

  • Connection-stage abort marking AGGREGATED: confirmed as intended. The abort path calls interrupt(). connection_stage_supervisor_reset() then clears the abort flag, and run 2 starts. Because the aggregate now includes a truncated run, AGGREGATED is marked Interrupted: "true", while the per-run flag stays on the aborted run only. Exit code 2 is unchanged. The PR description now states this, under "Also affected, besides Ctrl+C".
  • elapsed < 3.5 under TSAN: at 522985a every TSAN cell passed, including both TSAN Plaintext cells (single endpoint and cluster) and the TSAN STRESS cells. Those cells run test_interrupt_stops_run_count. SIGINT-to-exit there is one 1 Hz tick plus the thread join, so the bound keeps about 2.5 s of headroom. We'll widen it if a sanitizer cell ever comes close.
  • "skipping the remaining runs" wording when the signal lands in the settle pause: fair point. Handle SIGTERM like Ctrl+C so --json-out-file stays valid #706 (SIGTERM) rewrites this exact line to name the signal, so the wording will be tidied there rather than here.

@fcostaoliveira
fcostaoliveira merged commit b1c46f4 into master Oct 16, 2026
129 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
After the rebase onto #698, its "skipping the remaining runs" note still
said "Interrupted by user (Ctrl+C)" for a SIGTERM. It now names the
signal, like the per-run interrupt message, through one helper.

A second SIGINT or SIGTERM now resets the handler to the default action
and re-raises, so it terminates memtier immediately. This keeps a way out
of a shutdown that is stuck, which a process without a handler always had.

Document the interrupt behaviour in the README and the --run-count help
line (and man page), and add tests: SIGTERM during run 1 and in the
settle pause of --run-count 3, and a second SIGTERM killing memtier while
it is held in open() of a --json-out-file FIFO.

Fixes #704

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
After the rebase onto #698, its "skipping the remaining runs" note still
said "Interrupted by user (Ctrl+C)" for a SIGTERM. It now names the
signal, like the per-run interrupt message, through one helper.

A second SIGINT or SIGTERM now resets the handler to the default action
and re-raises, so it terminates memtier immediately. This keeps a way out
of a shutdown that is stuck, which a process without a handler always had.

Document the interrupt behaviour in the README and the --run-count help
line (and man page), and add tests: SIGTERM during run 1 and in the
settle pause of --run-count 3, and a second SIGTERM killing memtier while
it is held in open() of a --json-out-file FIFO.

Fixes #704

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Ctrl+C does not stop the remaining --run-count runs; each one runs ~1 s more of load and is counted in BEST/WORST/AGGREGATED

1 participant