Skip to content

[Bug]: caller timeout resets the shared HAKeeper client and cascades connection failures #25868

Closed

Description

@LeftHandCold

Summary

A caller-scoped context.Canceled or context.DeadlineExceeded returned by a managed HAKeeper request currently closes the shared HAKeeper client.

The client is shared by connection-ID allocation, CN heartbeat, cluster refresh, task service, and other CN control-plane requests. One request reaching its own deadline therefore forces unrelated requests through HAKeeper rediscovery and can turn a single timeout into a connection-admission failure cascade.

Root cause

Every managed HAKeeper method currently resets the shared client on any request error:

result, err := c.getClient().sendCNHeartbeat(ctx, hb)
if err != nil {
    c.resetClient()
}

AllocateIDByKeyWithBatch, used by frontend connection admission, does the same while holding the managed-client mutex.

A caller context error only states that this request can no longer wait. It is not evidence that the shared MORPC transport is unusable. Closing that transport also interrupts concurrent users and makes the next user synchronously discover and reconnect to HAKeeper.

Impact

This caused the SSB phase in TKE mergerun job 88168675381 to fail while opening the fifth q1.3 connection:

  • 07:27:36.464 UTC: the established HAKeeper TCP connection was closed.
  • 07:27:36.469 UTC: one frontend connection failed with failed to get connection ID from HAKeeper: context deadline exceeded.
  • The next connection was forced into synchronous HAKeeper rediscovery; dials to log-0 and log-1 each reached the one-second connect timeout.
  • 07:27:38.884 UTC: the SSB q1.3 connection failed with the same connection-ID error.
  • In the same cascade, CN heartbeat, task service, and cluster refresh reported HAKeeper deadline errors.
  • HAKeeper discovery succeeded again immediately afterward, and the next SSB query succeeded. The LogService pods had no restart, election, OOM, or raft failure in the incident window.

This is a pre-existing availability bug. The failure occurs during frontend routine creation, before SQL execution and before the trace changes in PR #25841.

Reproduction / evidence

On current main at 4d78bc66670418fbdeac2b18b07b2ef5b08b1d72, a deterministic package-level fault injection makes sendCNAllocateID return each caller context error and then inspects the managed client.

Expected: the request returns its context error and the shared client remains available.

Actual on unmodified production code:

=== RUN   TestAllocateBatchIDKeepsClientOnContextError/canceled
Error: Not same: expected existing client, actual nil
=== RUN   TestAllocateBatchIDKeepsClientOnContextError/deadline_exceeded
Error: Not same: expected existing client, actual nil
--- FAIL: TestAllocateBatchIDKeepsClientOnContextError

The client is deterministically reset for both errors.

Proposed fix

  • Do not reset the shared HAKeeper client for context.Canceled or context.DeadlineExceeded.
  • Continue returning the original context error to the caller.
  • Preserve current reset, reconnect, and retry behavior for EOF, connection-close, NoHAKeeper, and all other non-context errors.
  • Apply the rule consistently to every managed HAKeeper operation because all of them share the same client.
  • Add a regression test proving that a timed-out ID allocation leaves the shared client reusable and that the next allocation can succeed without rediscovery.

The change must not alter connection-ID values, allocation batch size, public interfaces, timeouts, or retry counts.

Acceptance criteria

  • A canceled or expired HAKeeper request does not close the shared managed client.
  • The original caller still receives context.Canceled or context.DeadlineExceeded.
  • A following ID allocation reuses the same client and can succeed.
  • EOF/connection failures still reset and reconnect exactly as before.
  • Focused tests pass repeatedly in normal and race modes.
  • Full pkg/logservice tests, build, vet, and relevant frontend tests pass.

Activity

  1. self-assigned this
    on Jul 19, 2026
  2. added
    severity/s0
    and removed on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions