Repository navigation
Treat a deadline-clamped reconnect as at the deadline when it fires - #873
Conversation
A never-started cluster client whose CLUSTER SLOTS retry is due at the --test-time deadline must fail the run (#667). next_reconnect_delay() clamps that retry to the deadline, and handle_reconnect_timer_event() then asks run_is_over(), which compares the wall clock with the deadline, allowing 1 ms for the timer firing early. On Linux libevent times events with CLOCK_MONOTONIC_COARSE, whose tick is 1-4 ms, and maps it to wall time through an offset sampled once per 5 s. The clamped timer can therefore fire more than 1 ms before the wall-clock deadline. run_is_over() then says the run is not over, the retry reconnects, the slot map is now good, and the client completes setup and ends normally at its first reply: memtier exits 0 (#852). Remember the deadline a reconnect timer was clamped to, and once that timer has fired, report that deadline as passed. A retry armed before the deadline with its normal backoff is unchanged, and a deadline that moved later since (the client started) is still judged by the clock. The unit test arms a clamped retry 100 ms before the deadline and fires its handler at once, staging the early timer: without the fix it reconnects and the run does not fail. Fixes #852 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…test's gap m_reconnect_deadline is documented as zero when no clamped timer is pending; clear it once the timer has fired and the deadline was copied. The unit test's deadline was 100 ms away, which a stalled sanitizer runner could overrun before the handler runs; 500 ms keeps the 1 s backoff clamped with more room. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks, this reads well. The root-cause write-up is clear: the timer fires early because of libevent's coarse clock, so it's about when the retry fires, not when it was scheduled (#812). The unit test fails both checks on master's
The fix looks solid to me. I'd just like the second point confirmed before merge. (would file this as a comment, not a formal block) |
connect() and disconnect() free a pending reconnect timer; clear the deadline it was clamped to there as well, so m_reconnect_deadline is zero whenever no clamped timer is pending, as its comment says. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks.
Sanitized |
… one is sticky Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both done in 74bfa4e: the two |
|
Thanks. On the three points:
|
Keep both new unit tests in reconnect_siblings_test.cpp (#894's connection-rejection test and this PR's deadline-retry test). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #852.
test_cluster_slots_never_started_client_fails_at_deadlinefails intermittently in CI (run 40130526066). A cluster client whose CLUSTER SLOTS keeps failing never starts. With unlimited reconnects its last retry is clamped to fire exactly at the--test-timedeadline (next_reconnect_delay()). When the timer fires,run_deadline_passed()checks the wall clock against the deadline with 1 ms of slack.libevent on Linux times events with a coarse monotonic clock (1–4 ms ticks), so the timer can fire more than 1 ms early by the wall clock. The check then says the run isn't over, and the retry reconnects and gets a good slot map. The client ends normally at its first reply, so memtier exits 0 instead of failing the run for a client that never started. #812 fixed when the retry is scheduled; this is about when it fires.
Fix (
shard_connection.cpp/.h, +16):next_reconnect_delay()records the deadline it clamped a reconnect to.run_deadline_passed()treats that deadline as passed, whatever the wall clock says.Unchanged:
--max-reconnect-attempts(never clamped, --reconnect-on-error with unlimited --max-reconnect-attempts: run never ends when the server stays down, even past --test-time #656)Test:
test_deadline_retry_fires_early()intests/unit/reconnect_siblings_test.cpp. It arms a clamped retry 100 ms before the deadline and runs the timer handler at once, standing in for a timer that fires early. It checks that the client doesn't reconnect and that the run fails. A second case checks that a retry 2 s before the deadline still reconnects. With master'sshard_connectionfiles the new test fails both checks; with the fix it passes.Results (ASan + UBSan, libevent 2.1.12, Ubuntu 24.04 container):
test_cluster_slots_bad_reply.py(cluster) passes 20/20 in each of 5 iterations.make checkpasses, and clang-format is clean.The end-to-end flake doesn't reproduce locally: this machine's coarse clock ticks at 1 ms, which the existing slack covers. That's why the regression test is a unit test.
🤖 Generated with Claude Code
Note
Medium Risk
Changes when timed benchmark runs stop reconnecting and fail vs succeed exit; scope is limited to unlimited reconnect + --test-time deadline clamping.
Overview
Fixes #852: when unlimited reconnects clamp the next retry to the
--test-timedeadline, libevent on Linux can fire that timer 1–4 ms early (coarse monotonic clock).run_deadline_passed()only allowed 1 ms slack on the wall clock, so the run was treated as not over, the client reconnected, completed setup, and exited 0 instead of failing a never-started cluster client.shard_connectionnow records the deadline whennext_reconnect_delay()shortens the backoff (m_reconnect_deadline), copies it tom_fired_reconnect_deadlinewhen that reconnect timer fires, andrun_deadline_passed()treats that fired deadline as passed regardless of wall time. Pending deadline state is cleared when reconnect timers are cancelled. Retries well before the deadline are unchanged.Adds
test_deadline_retry_fires_early()inreconnect_siblings_test.cppto simulate an early-fired deadline-clamped retry and assert no reconnect + run failure, plus a control case that still reconnects before the deadline.Reviewed by Cursor Bugbot for commit 73adaf2. Bugbot is set up for automated code reviews on this repo. Configure here.