Skip to content

fix(reconnect): don't kill thread on duplicate connection error while a reconnect is already pending - #392

Merged
fcostaoliveira merged 3 commits into
redis:masterfrom
fcostaoliveira:fix/attempt-reconnect-dup-error-during-pending-reconnect
May 22, 2026
Merged

fcostaoliveira merged 3 commits into
redis:masterfrom
fcostaoliveira:fix/attempt-reconnect-dup-error-during-pending-reconnect

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #391.

What changed

shard_connection.cpp::attempt_reconnect() previously collapsed three semantically distinct conditions into a single terminal else branch:

  1. !reconnect_on_error — caller opted out (terminal: yes)
  2. m_reconnecting == true — a reconnect is already pending (terminal: no — should be a no-op)
  3. m_reconnect_attempts >= max_reconnect_attempts — configured cap reached (terminal: yes)

Case 2 is the bug. During a real failover, libevent delivers a small storm of connection-error callbacks per dead connection (EOF + stray TLS read errors). The first enters the happy path and schedules a reconnect timer; the rest land in the else branch and call event_base_loopbreak(), killing the per-thread event loop regardless of --max-reconnect-attempts value (including the documented "0 = unlimited" semantic).

Fix

Add an else if for the "already reconnecting" case that silently returns. The terminal else keeps its existing behaviour for the two cases that are terminal.

Test plan

  • Existing tests pass (make test).
  • Manual: trigger a DB-node reboot mid-bench against a Redis Enterprise cluster; confirm threads survive the connection-error storm and throughput recovers after the failover instead of falling to 0 and staying there.

Issue link

Full reproduction + log evidence in #391.


Note

Medium Risk
Changes core reconnection control flow in shard_connection::attempt_reconnect, which can affect benchmark thread liveness under error conditions; regression coverage is added to reduce risk.

Overview
Prevents benchmark threads from being spuriously restarted when libevent delivers multiple connection-error callbacks while a reconnect timer is already pending (especially with --max-reconnect-attempts=0 unlimited), by treating those duplicate callbacks as a no-op instead of breaking the event loop.

Adds a regression test (test_reconnect_unlimited_no_spurious_thread_restart) that repeatedly kills connections and asserts the misleading "Maximum reconnection attempts (0) exceeded" message never appears and the run exits successfully. CI/ASAN/UBSAN workflow test step timeouts are increased from 10 to 15 minutes to reduce flakiness for the expanded test suite.

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

fcostaoliveira and others added 2 commits May 22, 2026 02:21
…pending

Fixes redis#391.

shard_connection::attempt_reconnect() collapsed three semantically distinct
cases into one terminal else, so the second callback in a libevent error
storm (EOF + stray TLS reads during failover) always called
event_base_loopbreak() — even with --max-reconnect-attempts=0 (unlimited).

Add an else-if for the already-reconnecting case that silently returns;
the in-flight reconnect timer decides what to do when it fires.

Also adds a regression test that verifies the misleading
"Maximum reconnection attempts (0) exceeded" message never appears when
unlimited reconnects are configured.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The ASAN Single Endpoint TCP TLS job timed out after 597 s (9.95 min),
killing the step 2 s after all 99 tests had already passed. The CI TLS
matrix jobs were also running at 10m5–10m20s — squarely at the limit.
TSAN already uses 15 min; align the others to the same ceiling.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/attempt-reconnect-dup-error-during-pending-reconnect branch from e33355b to 0b8e396 Compare May 22, 2026 05:43
@jit-ci

jit-ci Bot commented May 22, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

RLTest's assertFalse signature is assertFalse(val, depth=0, message='').
Passing the message string as a positional second argument landed it in
depth, causing TypeError: can only concatenate str (not "int") to str
when RLTest computed depth + 1 internally.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit d52544b into redis:master May 22, 2026
65 checks passed
@fcostaoliveira fcostaoliveira added this to the 2.4 milestone Jun 1, 2026
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.

attempt_reconnect kills the benchmark thread on duplicate connection errors while a reconnect is already pending

2 participants