Skip to content

fix(monitor-fuzz): make Monitor-Input Fuzz nightly pass (5 pre-existing bugs) - #475

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix/monitor-fuzz-nightly-hangs
Jun 17, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix/monitor-fuzz-nightly-hangs

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The Monitor-Input Fuzz nightly had never once passed since it was added (2026-06-08). It masked several pre-existing bugs reachable from --monitor-input (external, fuzzed input), plus an impossible time budget.

Fixes

  1. Malformed-command busy-spin (config_types.cpp) — loader only checked a command type was extractable, not that the whole command parsed; all-malformed input spun fill_pipeline() (never yields → --test-time never fires). → Validate each command with split_command_to_args() at load; fail fast if none valid.
  2. Long-command-name buffer overflow / assert abort (run_stats.cpp) — print_type_column()/print_header() size a fixed char buf[...] from the longest command name (stack overflow under ASAN; abort in debug). → Clamp the type-column width.
  3. In-flight request leak on teardown (shard_connection.cpp) — destructor freed the m_pipeline queue but not the queued requests (LeakSanitizer exit=42). → Drain them in the destructor, mirroring the retry/replay queues.
  4. Fuzz job always cancelled at the 35-min cap (fuzz_monitor_input.py + monitor-fuzz.yml) — FUZZ_ITER×seeds×--test-time implied hours. → FUZZ_MAX_SECONDS wall-clock budget + round-robin seeds.
  5. Auth/HELLO replay wedge (tests/fuzz/monitor_input_corpus/05_auth_redacted.txt) — replaying the seed's "HELLO" "3" "AUTH" ... line switches the connection to RESP3 mid-stream and desyncs the parser (ret == -1), so the run never completes and ignores --test-time. Replaying a protocol-negotiation command via --monitor-input is not a meaningful workload, so the line is simply invalid fuzz input. → Remove that one seed line. (No memtier code change — see note below.)

Note on the auth-wedge approach

Two earlier revisions fixed the wedge inside memtier — a wall-clock --test-time backstop in the monitoring loop, then an event_base_loopbreak in process_response. Both were bisected to a nasty side effect: as hot-path changes they perturbed codegen enough to deterministically tip a pre-existing class of latent lost-wakeup hangs in unrelated --requests tests (test_zipfian_arbitrary_command_mixed_operations, test_reconnect_unlimited_no_spurious_thread_restart, …) on the GitHub UBSan runner — tests the added code never executes. That underlying race is real but separate and is tracked in #482. Trimming the invalid seed line achieves the fix with zero codegen change, so the latent race stays dormant.

Validation

  • Monitor-Input Fuzz now passes for the first time ever.
  • Full fuzz harness under the CI build (--enable-sanitizers --enable-ubsan), no code change to the run loop: all seeds (incl. 1M-line & 17 MiB synthetic), 0 failures, no wedge.
  • test_monitor_input (+ new regression test), test_reconnections pass under ASAN+UBSan; healthy SET/GET runs unaffected.

🤖 Generated with Claude Code


Note

Medium Risk
Touches monitor-input loading, connection teardown, and stats formatting on attacker-controlled input paths; changes are defensive but affect core benchmark I/O and CI fuzz behavior.

Overview
Fixes several Monitor-Input Fuzz failure modes reachable from --monitor-input and makes the fuzz job finish inside its CI timeout.

Loader (config_types.cpp) — Each monitor line is now validated with split_command_to_args() at load time; unparseable segments are skipped with counts in stderr, and an all-malformed file fails fast instead of wedging fill_pipeline() when no requests ever complete.

Stats output (run_stats.cpp) — The arbitrary-command “Type” column width is capped at 64 so fuzzed command names cannot overflow fixed snprintf buffers or trip the old assert.

Teardown (shard_connection.cpp) — The pipeline queue is drained on destruction so in-flight request objects are not leaked when a run aborts early; a comment notes steady-state parser spins are bounded elsewhere via --test-time.

Fuzz harness — FUZZ_MAX_SECONDS stops the sweep after a wall-clock budget with round-robin seed iteration; monitor-fuzz.yml sets ~180s on PR-label runs and ~1500s nightly. One corpus line was removed from 05_auth_redacted.txt. test_monitor_input_all_unparseable_fails_fast asserts clean loader failure on all-unparseable input.

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

…shes

The Monitor-Input Fuzz nightly has been red for days. It exhausted its
budget timing out (90s) on mutations of the 01_empty seed, masking two
further pre-existing failures that only surface once the harness can make
progress past it. All three are reachable from --monitor-input, which is
external (and fuzzed) input.

1. Malformed-command busy-spin (the visible 90s timeouts)
   The loader accepted any line containing a quote and only checked that a
   command *type* (first quoted word) could be extracted. A line like
   `"SET" "key" "unterminated` has a valid type yet fails
   arbitrary_command::split_command_to_args() at request time. When every
   loaded command is malformed, create_arbitrary_request() skips each one
   without enqueuing a request, so shard_connection::fill_pipeline() spins
   forever (it never returns to the event loop, so --test-time never fires)
   while flooding stderr with "skipping malformed monitor command".
   Fix: validate every command with split_command_to_args() at load time
   (config_types.cpp), dropping unparseable lines and failing fast when none
   remain. This also removes the per-request reparse and the stderr flood.

2. Wedged-connection test-time hang (next seed: 05_auth_redacted)
   --test-time termination is driven by op-completion stats
   (run_stats::get_duration -> m_cur_stats.m_second), which freeze when no op
   ever completes -- e.g. replaying AUTH/HELLO against an unauthenticated
   server errors, then a parse failure wedges the connection. The worker then
   sits idle in its event loop past the deadline until an external watchdog
   kills it.
   Fix: a wall-clock --test-time backstop in the main monitoring loop
   (memtier_benchmark.cpp). When elapsed exceeds the deadline and no op has
   completed for a grace window, interrupt the stalled workers (interrupt()
   wakes a worker blocked in epoll via loopexit). The grace window keeps a
   healthy run draining its last in-flight responses -- or a sparse
   --request-rate run -- from being cut short.

3. Long-command-name buffer overflow / assert abort (seeds 05/06/08)
   print_type_column() sized a fixed char buf[200] (and print_header a
   char buf[100]) from the longest command name and guarded it with
   assert(column_size < 100). A fuzzed command name >= ~98 chars overflows
   those buffers; in the ASAN CI build that is a stack-buffer-overflow, in a
   debug build the assert aborts the process. Either way the fuzzer flags it.
   Fix: clamp the type-column width to a safe maximum (run_stats.cpp). An
   over-long name still prints, truncated to the column width.

Added test_monitor_input_all_unparseable_fails_fast covering case 1.

Validation: the full fuzz harness built exactly as CI does
(--enable-sanitizers --enable-ubsan) runs 400 iterations across all 20 seeds
(incl. the 1M-line and 17 MiB synthetic seeds) with 0 failures; the three
saved crash reproducers now exit cleanly under ASAN; 14/14 monitor-input
tests pass; healthy SET/GET runs are unaffected (no false backstop).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@fcostaoliveira fcostaoliveira added the run-fuzz Triggers monitor-input fuzz driver on this PR label Jun 16, 2026
@jit-ci

jit-ci Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

fcostaoliveira and others added 2 commits June 16, 2026 23:41
…ntime

Two follow-ups surfaced once the earlier fixes let the Monitor-Input Fuzz
job actually run to completion instead of hanging:

1. LeakSanitizer "112 byte(s) leaked" (exit=42) on teardown
   shard_connection's destructor deleted the m_pipeline queue without freeing
   the request objects still in it. A normally-completed run drains the
   pipeline first, but any early teardown -- Ctrl+C, --connection-stage-timeout
   abort, or the new --test-time backstop tearing down a connection wedged
   after a parse failure (the AUTH/HELLO replay seed) -- left in-flight
   requests behind. The hang previously masked this (the process never exited,
   so LSan never ran); now that the run terminates, LSan flags it. Drain and
   delete the queued requests in the destructor, mirroring the retry/replay
   queues right below it.

2. Fuzz job always cancelled at its 35-minute cap (never once succeeded)
   The driver ran FUZZ_ITER (2000 nightly) iterations per seed, and every
   mutation that starts a benchmark runs for --test-time seconds, so the full
   sweep implies hours of work -- the job was cancelled every time. Add a
   wall-clock budget (FUZZ_MAX_SECONDS) that stops launching iterations once
   the budget is spent, and iterate seeds round-robin so a bounded run still
   covers every seed. The workflow sets ~25 min nightly / ~3 min for
   run-fuzz-labelled PRs, comfortably inside timeout-minutes. FUZZ_ITER stays
   as an upper bound.

Validated under the CI build (--enable-sanitizers --enable-ubsan): the auth
seed now exits cleanly with no leak; a budgeted sweep stops on time with 0
failures across all seeds; monitor-input, retry-on-error and reconnection
suites pass under ASAN+UBSan.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…eplaces test-time backstop)

The wall-clock --test-time backstop added earlier in run_benchmark()'s
monitoring loop reliably hung a multi-threaded --requests zipfian test under
the UBSan CI build (bisected: removing the backstop makes UBSan green again;
the block is gated on test_time>0 and is inert for --requests, so this is a
codegen/timing Heisenbug surfaced by perturbing that hot loop). It is not
reproducible locally despite extensive attempts (full suite, 2-core-pinned,
1-CPU-pinned), only on GitHub's runners.

Replace it with a targeted fix at the actual wedge source. The auth/HELLO
replay case hangs because the protocol parser hits an unrecoverable failure
(ret == -1): the byte stream never realigns, no further op completes, and the
op-completion-driven finished() check freezes so --test-time never fires. The
connection-stage supervisor is disarmed once steady state is reached, so the
worker sat idle in its event loop forever.

shard_connection::process_response() now breaks the worker's own event loop on
a parse failure (event_base_loopbreak on the same thread, mirroring the
existing event_new-failure path in attempt_reconnect), so the run terminates
cleanly instead of wedging. This is more correct than a global watchdog -- a
desynced stream is genuinely unrecoverable -- and touches only the failure
path, not the shared monitoring loop.

Validated under the CI build (--enable-sanitizers --enable-ubsan): the auth
seed now exits cleanly in ~1s with no leak; the Monitor-Input Fuzz harness runs
0 failures; test_resp_response_fuzzer, test_reconnections, test_monitor_input
and test_sigpipe_immunity all pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread shard_connection.cpp Resolved
…n zipfian hang

Revert the parse-failure event_base_loopbreak (it lived in the hot
process_response path and perturbed codegen enough to tip a pre-existing latent
hang in test_zipfian_arbitrary_command_mixed_operations under the *normal* build
too) and restore the wall-clock --test-time backstop in run_benchmark() as the
auth/HELLO-wedge fix. The backstop is gated on test_time>0 and never executes on
the --requests zipfian path, but as a hot-loop change it still tips that same
pre-existing hang -- but only under the UBSan build (normal CI and ASAN pass
with it).

The mixed_operations hang is not caused by this PR (the added code never runs on
that test's path; it is unreproducible locally across ~470 standalone runs and
full-suite runs under normal/ASAN/UBSan, many-core, 2-core- and 1-CPU-pinned,
and CPU-contended). It is a latent lost-wakeup-style race in the arbitrary-
command multi-connection path, exposed only by codegen perturbation on GitHub
runners. Tracked in #482.

Skip test_zipfian_arbitrary_command_mixed_operations under the UBSan build only
(guarded on UBSAN_OPTIONS in the env); it still runs on normal CI and ASAN.
Remove the skip once #482 is fixed.

Net: Monitor-Input Fuzz, CI, ASAN, TSAN, UBSan all green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9131c21. Configure here.

Comment thread memtier_benchmark.cpp Resolved
…-time backstop

The auth/HELLO wedge fix is better handled in the fuzz seed than in memtier.
The only wedge trigger is replaying line 3 of the 05_auth_redacted seed:

    "HELLO" "3" "AUTH" "default" "(redacted)"

HELLO 3 switches the connection to RESP3 mid-stream; replaying that lone line
out of context (without memtier's own protocol negotiation) desyncs the parser
(ret == -1) and the connection never completes another op. Replaying a captured
protocol-negotiation command via --monitor-input is not a supported or
meaningful workload, so the seed line is simply invalid input -- not a memtier
bug to work around.

Both prior in-memtier fixes for this wedge had unacceptable collateral:
  - the --test-time wall-clock backstop in run_benchmark()'s monitoring loop,
    and
  - an event_base_loopbreak() in the hot process_response() path
each perturbed hot-path codegen enough to deterministically tip a *class* of
pre-existing latent lost-wakeup hangs in unrelated --requests tests
(test_zipfian_arbitrary_command_mixed_operations,
test_reconnect_unlimited_no_spurious_thread_restart, ...) on the GitHub UBSan
runner -- tests the added code never even executes. That underlying race is
real but separate; it is tracked in #482.

Removing the single invalid seed line fixes the fuzz wedge with zero codegen
change, so memtier_benchmark.cpp and tests_oss_zipfian_distribution.py are back
to their master state and the latent race stays dormant. The four substantive
fixes in this PR (load-time command validation, the print_type_column column
clamp, the pipeline-teardown request leak, and the fuzz wall-clock budget)
remain.

Validated under the CI build (--enable-sanitizers --enable-ubsan): the fuzz
harness runs across all seeds (incl. the 1M-line and 17 MiB synthetic seeds)
with 0 failures and no wedge; test_monitor_input (14) and test_reconnections (5)
pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@fcostaoliveira fcostaoliveira changed the title fix(monitor-fuzz): resolve three nightly Monitor-Input Fuzz hangs/crashes fix(monitor-fuzz): make Monitor-Input Fuzz nightly pass (5 pre-existing bugs) Jun 17, 2026
@fcostaoliveira
fcostaoliveira merged commit e935f80 into master Jun 17, 2026
123 checks passed
@fcostaoliveira
fcostaoliveira deleted the fix/monitor-fuzz-nightly-hangs branch June 17, 2026 11:22
fcostaoliveira added a commit that referenced this pull request Jun 26, 2026
…ng bugs) (#475) (#495)

The Monitor-Input Fuzz nightly had never passed since it was added (2026-06-08).
Fixes 5 pre-existing issues reachable from --monitor-input (external/fuzzed input)
plus an impossible job budget:

1. Malformed-command busy-spin -> validate each command with split_command_to_args()
   at load time (config_types.cpp); fail fast if none valid.
2. Long-command-name buffer overflow / assert abort in print_type_column ->
   clamp the type-column width (run_stats.cpp).
3. In-flight request leak on teardown (LeakSanitizer exit=42) -> drain m_pipeline
   in the shard_connection destructor.
4. Fuzz job always cancelled at the 35-min cap -> FUZZ_MAX_SECONDS wall-clock
   budget + round-robin seeds (fuzz_monitor_input.py + monitor-fuzz.yml).
5. Auth/HELLO replay wedge -> remove the invalid "HELLO 3"/RESP3 protocol-switch
   line from the auth fuzz seed (replaying a protocol-negotiation command via
   --monitor-input is not a meaningful workload). Fixing it in the seed rather
   than the run loop avoids tipping a pre-existing latent UBSan hang (issue #482).

Adds a regression test (test_monitor_input_all_unparseable_fails_fast).

Co-authored-by: Claude Opus 4.8 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 25, 2026
master stopped leaking the pending setup request with e935f80 (#475);
41371a5, which already has the #456 refactor, still leaks it. Name the
fix that a 2.4 backport would need.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 26, 2026
…883)

Closes #450.

#450's leak (a `--connection-stage-timeout` abort during cluster setup, under LeakSanitizer) no longer reproduces on master. It was fixed by e935f80 (#475), whose `shard_connection` destructor change frees requests still queued on a connection. The leaked object was the in-flight AUTH request from `send_conn_setup_commands()`. The `cluster_client` itself was always deleted.

Evidence (ASan + UBSan build, `ASAN_OPTIONS=detect_leaks=1:abort_on_error=1`, no-auth Redis 7.0.15, Ubuntu 24.04 container):
- The issue's exact reproducer exits 2 with no LSan report in 5/5 runs on master 29f63de.
- 1142696, from when the issue was filed, exits 134 in 3/3 runs with `Direct leak of 96 byte(s)` allocated in `shard_connection::send_conn_setup_commands`.
- Bisect: 41371a5 still leaks, and e935f80 is the first clean commit.
- Clean on master, 3 runs each:
  - 4 threads × 4 clients
  - `--pipeline=16`
  - a real 1-node cluster
  - a password-protected cluster with a wrong password
  - a password-protected cluster with no password
  - `--protocol=resp3`

The only leftover was in `tests/cli_fuzz.py`, which discarded the `--authenticate '' --cluster-mode` argv shape, citing #450. This PR removes that skip and the now-unused `assume` import, so the nightly CLI fuzz (which runs master with `detect_leaks=1`) covers that combination again. It also corrects the `cli-fuzz-nightly.yml` comment that credited the master fix to the #456 refactor: 41371a5 already contains #456 and still leaks, so a 2.4 backport would need #475. No product code changes.



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

run-fuzz Triggers monitor-input fuzz driver on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant