Repository navigation
Don't roll per-second stats before a client's start time is set (#708) - #714
Conversation
With --reconnect-on-error, a client whose first connect fails records a connection error through run_stats::update_connection_error() before set_start_time() has run. roll_cur_stats() then measured the current second from a zero m_start_time, so m_cur_stats moved to an epoch-sized second (~1.79e9). set_start_time() does not reset it and later rolls never go back, so get_duration() reported the run over as soon as the client connected: a --test-time run sent 0 requests and exited 0, and the JSON time series was keyed by epoch seconds (also with --requests). Make roll_cur_stats() a no-op until the run has started. The early connection errors are still counted in m_totals and in second 0, which the run's first second then continues. Fixes #708 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Assert that Connection Errors equals the logged connection errors (at least two per client), so dropping the errors recorded before the start fails the test, and that the server saw exactly Count GET/SET calls. Cover --requests too. Fail with a clear message if another process took the port before redis was started on it. Refs #708 Co-Authored-By: Claude Opus 5.5 <[email protected]>
b7e8234 to
7dda96a
Compare
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. The root-cause writeup made the one-liner easy to follow. Returning early in A couple of small questions:
The core fix looks good to me. I'd just like to hear back on the test assertion before this merges. |
The "Connection error:" line is only printed when errno is set, while attempt_reconnect() always counts the error, so an exact match with the log could flake. Assert at least two errors per client instead, which still fails if the errors recorded before the start are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Re the automated review:
|
Problem
With
--reconnect-on-error, when a client's first connect fails and a later reconnect succeeds (for example, redis started a couple of seconds after memtier), a--test-timerun stops as soon as the connection is up. It sends 0 requests and still exits 0. The JSON hasCount 0and"Total duration": 0, and itsTime-Seriekeys are epoch seconds (['0', '1792151574', ...]). With--requeststhe run completes, but its time series is keyed the same way.Root cause
shard_connection::attempt_reconnect()callsrun_stats::update_connection_error()before the client has started. That function callsroll_cur_stats(), which computessec = ts_diff(m_start_time, *ts) / 1000000whilem_start_timeis still{0,0}. Som_cur_statsis reset to a second near 1.79e9.set_start_time()leavesm_cur_statsalone, and later rolls never go back. Once the client connects,get_duration()(which ism_cur_stats.m_second) is already>= test_time, andclient::finished()ends it.Fix
roll_cur_stats()returns early while!has_started(). Errors recorded before the start are still counted inm_totalsand inm_cur_statssecond 0, which the first real second then continues. This is a single-line behaviour change inrun_stats.cpp.run_stats::merge()path for never-started clients readsm_totals.m_connection_errorsand does not touch the per-second buckets, so it is unaffected. For clients that start late, the early errors are now in bucket 0 and in the totals, and both merge normally. SoConnection Errorsstays correct (6 in the repro, before and after).--test-timedeadline (set_end_time_at). It does not touchroll_cur_stats()/get_duration(), so the two changes are independent. With this fix, a late-starting client'sget_duration()counts from its real start again, which is what End a --test-time run at its deadline while reconnecting to a dead server #666's deadline logic expects.Test evidence
New
tests/test_reconnect_late_server_start.py(standalone only) has two cases. Each starts memtier (-t 1 -c 2 --reconnect-on-error --connection-stage-timeout=0) against an empty port and starts redis on that port 2 s later:test_server_started_after_memtieruses--test-time=5.test_server_started_after_memtier_requestsuses--requests=1000.Both assert:
Connection Errors== the number of logged(TLS c|C)onnection error:lines, and at least 2 per client;Count > 0;Count== the server'scmdstat_get+cmdstat_setcalls;--test-time:Total durationin [4 s, 7 s];--requests: Count == 2000.If another process took the port before redis started on it, the test fails with a clear message instead of timing out.
[0, 1792153397, ...].m_cur_stats.reset(0)in the guard (drops the pre-start errors)Connection Errors 2 == 6set_start_time()clearsm_statsand resetsm_cur_statsConnection Errors 0 == 6Manual repro, master vs fix:
These existing tests pass locally on this branch:
test_reconnections.pytest_reconnect_unlimited_no_spurious_thread_restart,test_connection_kill_with_reconnect_is_not_rerunandtest_dropped_in_flight_requests_do_not_stall_client.Fixes #708
Affected versions
2.3.0 through 2.5.2 (latest) and master. On master the result is a 0-op run. In 2.5.x the silent worker-thread restart hides it: the run takes extra wall time, and the JSON reports
Connection Errors0.update_connection_error()→roll_cur_stats()on the reconnect path. The first tag that contains it is 2.3.0.🤖 Generated with Claude Code
Note
Low Risk
Narrow guard in stats rolling for the pre-start reconnect path; regression tests cover late server startup with --reconnect-on-error.
Overview
Fixes #708: with
--reconnect-on-error, pre-start connection errors no longer advance per-second stats using an unsetm_start_time, which used to jumpm_cur_stats.m_secondto epoch-scale values and make--test-timeruns exit immediately with 0 requests and bogus JSONTime-Seriekeys.run_stats::roll_cur_stats()now returns early while!has_started(), so errors before the first successful connect stay in second 0 and totals until the real start; duration and time-series indexing behave normally after connect.Adds
tests/test_reconnect_late_server_start.py: starts memtier against a closed port, brings up redis after 2s, and checks exit code, connection errors, request counts vs servercommandstats, runtime bounds for--test-time, and sane time-series keys for--test-timeand--requests.Reviewed by Cursor Bugbot for commit 47daa36. Bugbot is set up for automated code reviews on this repo. Configure here.