Skip to content

fix(logservice): retry transient HAKeeper backend closures - #28453

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-ut-control-plane-28443
Sep 9, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-ut-control-plane-28443

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

HAKeeper can report a failed MORPC transport generation as ErrBackendClosed instead of EOF. The managed client previously reset that generation but returned the error directly, so a transient control-plane disconnect escaped as a SQL failure during TestIssue26640CrossAccountRestoreRebindsPrivileges.

This change:

  • retries the transport-generation errors (ErrBackendClosed, connect/admission failures, connection reset) through the caller's existing deadline;
  • makes managedHAKeeperClient.Close terminal, prevents late failures from recreating a transport, and makes concurrent Close calls join the same cleanup result;
  • consolidates the retry regressions into deterministic table-driven tests, including deadline, business-error, in-flight-close, and concurrent-close cases.

The retry is bounded by every public HAKeeper request context. An allocation whose response is lost may consume an ID range, as the existing EOF retry already did, but the server's monotonic allocator prevents duplicate IDs from being returned.

Root cause and scope

Fixes #28452

Related: #28443, #28447, #28313, #28358

Validation

  • TestIssue26640CrossAccountRestoreRebindsPrivileges: -count=3, passed.
  • TestIssue28313EmptyRemoteDispatch: -count=5, passed.
  • HAKeeper retry/close focused tests: normal and -race -count=100, passed.
  • pkg/logservice: normal and race package runs passed with the known unrelated flaky TestNewServiceClosesStoreOnReplicaStartFailure excluded; that test still fails independently with listener address collisions/store-close leakage.
  • go vet ./pkg/logservice with the repository CGo flags and git diff --check, passed.

CI triage for run 34300098985

The source changes in this PR are limited to pkg/logservice. In the exact-head CI run:

  • Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed.
  • The UT coverage producer failed only at the unrelated existing test pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful, which returned context canceled; the producer report recorded no build failures and two failed events in pkg/sql/compile.
  • The downstream coverage merge failed because the required UT producer artifact was incomplete (prerequisites_ready=false); it did not calculate a coverage verdict.
  • The same TestIssue27261 test passed locally 10 times, and the PR retry/close focused tests passed locally 20 times normally and 100 times under -race; go vet and git diff --check passed.

No unrelated compile/pipeline change is included to mask this flaky coverage-only failure. This PR was not rebased and the existing PR base was not changed.

MORPC can report a failed HAKeeper transport generation as ErrBackendClosed instead of EOF. Treat connection-generation failures as retryable within the caller deadline, while preserving terminal managed-client shutdown semantics so an in-flight close cannot recreate the transport.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review of exact head 6232b85 against base bd8801a: no confirmed blocking regression found. COMMENT only, per the self-authored-PR instruction and explicit CI override.

Read both changed files and traced retry consumers, generation replacement, allocator/refill ownership, HAKeeper state-machine allocation, MORPC request/future cleanup and transport Close. The added backend/connect/admission/reset errors enter the existing retry loops; caller cancellation/deadline and business errors remain non-retryable. The existing 10 ms timer is stopped on exit and selects the caller context, with no additional nested retry owner added to GetScheduleCommands. Public request entry points validate a deadline. Transport reset remains generation-scoped, so a late failure cannot retire a newer client. This extends transport retries, not a promise that physical teardown or waiting for an existing mutex owner is interruptible by the waiting caller's context.

Close publishes the terminal transport state before detaching the client and holds the managed lock through inner cleanup. Concurrent/repeated callers observe the same cleanup result; prepareClientLocked rejects recreation after Close and getCurrentClient hides the detached transport. MORPC closes/cancels backend workers without a discovered reverse dependency on the managed lock. The change does not invalidate previously reserved local ID cache entries; its terminal guarantee is transport admission/recreation, not a newly enforced rejection on every cache-only allocation.

Lost allocation responses can consume an unused range on retry, as with the existing EOF path. The server's monotonic allocation state prevents this from turning into duplicate returned ranges; the request-ID variant keeps its stable request identity and server-side deduplication. Other affected state-update retries retain the existing method payloads and error behavior rather than introducing a new transaction identity. No new persistent map, background goroutine or retry queue is added. Existing future.Close/response.Release, refill-channel publication and executor/transport owners retain cleanup responsibility; failed closes remain reported through the existing logging path or the joined Close result. No new high-cardinality metric or per-attempt log stream is introduced.

Independent focused evidence: extracted this head's exact managed Close/getCurrentClient methods into a standard-library-only harness with a controllable inner transport. go test -race -count=100 passed with 32 concurrent Close callers, one cleanup invocation, cleanup-error convergence, terminal transport visibility and empty-client Close. This is a focused state-machine probe, not the complete native logservice package or an end-to-end transport-recovery run. I also inspected the added retry/deadline/in-flight-close tests and their hooks; the author reports focused race repetition and package/issue tests, with the unrelated listener-collision test explicitly excluded.

At the single snapshot, exact-head MatrixOne ALL CI run 34300098985 was in progress. Pending CI is not counted as green. Per override, no CI polling/waiting and no repository source changes.

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28453)

## Summary

HAKeeper can report a failed MORPC transport generation as
`ErrBackendClosed` instead of EOF. The managed client previously reset
that generation but returned the error directly, so a transient
control-plane disconnect escaped as a SQL failure during
`TestIssue26640CrossAccountRestoreRebindsPrivileges`.

This change:

- retries the transport-generation errors (`ErrBackendClosed`,
connect/admission failures, connection reset) through the caller's
existing deadline;
- makes `managedHAKeeperClient.Close` terminal, prevents late failures
from recreating a transport, and makes concurrent `Close` calls join the
same cleanup result;
- consolidates the retry regressions into deterministic table-driven
tests, including deadline, business-error, in-flight-close, and
concurrent-close cases.

The retry is bounded by every public HAKeeper request context. An
allocation whose response is lost may consume an ID range, as the
existing EOF retry already did, but the server's monotonic allocator
prevents duplicate IDs from being returned.

## Root cause and scope

- matrixorigin#28443 failed before its restore/privilege assertions. The embedded
LogService first reported checker/raft timing pressure, then MORPC
returned `backend connection closed` while allocating an ID. The failure
was a downstream control-plane transport error; the deeper first
scheduler/WAL/IO fault is not proven by that job.
- matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already
fixed by merged matrixorigin#28358, which is in this branch's base. The exact
regression test passes repeatedly on current main, so this PR
intentionally does not duplicate that dispatch implementation.

Fixes matrixorigin#28452

Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358

## Validation

- `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`,
passed.
- `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed.
- HAKeeper retry/close focused tests: normal and `-race -count=100`,
passed.
- `pkg/logservice`: normal and race package runs passed with the known
unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure`
excluded; that test still fails independently with listener address
collisions/store-close leakage.
- `go vet ./pkg/logservice` with the repository CGo flags and `git diff
--check`, passed.

## CI triage for run 34300098985

The source changes in this PR are limited to pkg/logservice. In the
exact-head CI run:

- Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed.
- The UT coverage producer failed only at the unrelated existing test
pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful,
which returned context canceled; the producer report recorded no build
failures and two failed events in pkg/sql/compile.
- The downstream coverage merge failed because the required UT producer
artifact was incomplete (prerequisites_ready=false); it did not
calculate a coverage verdict.
- The same TestIssue27261 test passed locally 10 times, and the PR
retry/close focused tests passed locally 20 times normally and 100 times
under -race; go vet and git diff --check passed.

No unrelated compile/pipeline change is included to mask this flaky
coverage-only failure. This PR was not rebased and the existing PR base
was not changed.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28453)

## Summary

HAKeeper can report a failed MORPC transport generation as
`ErrBackendClosed` instead of EOF. The managed client previously reset
that generation but returned the error directly, so a transient
control-plane disconnect escaped as a SQL failure during
`TestIssue26640CrossAccountRestoreRebindsPrivileges`.

This change:

- retries the transport-generation errors (`ErrBackendClosed`,
connect/admission failures, connection reset) through the caller's
existing deadline;
- makes `managedHAKeeperClient.Close` terminal, prevents late failures
from recreating a transport, and makes concurrent `Close` calls join the
same cleanup result;
- consolidates the retry regressions into deterministic table-driven
tests, including deadline, business-error, in-flight-close, and
concurrent-close cases.

The retry is bounded by every public HAKeeper request context. An
allocation whose response is lost may consume an ID range, as the
existing EOF retry already did, but the server's monotonic allocator
prevents duplicate IDs from being returned.

## Root cause and scope

- matrixorigin#28443 failed before its restore/privilege assertions. The embedded
LogService first reported checker/raft timing pressure, then MORPC
returned `backend connection closed` while allocating an ID. The failure
was a downstream control-plane transport error; the deeper first
scheduler/WAL/IO fault is not proven by that job.
- matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already
fixed by merged matrixorigin#28358, which is in this branch's base. The exact
regression test passes repeatedly on current main, so this PR
intentionally does not duplicate that dispatch implementation.

Fixes matrixorigin#28452

Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358

## Validation

- `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`,
passed.
- `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed.
- HAKeeper retry/close focused tests: normal and `-race -count=100`,
passed.
- `pkg/logservice`: normal and race package runs passed with the known
unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure`
excluded; that test still fails independently with listener address
collisions/store-close leakage.
- `go vet ./pkg/logservice` with the repository CGo flags and `git diff
--check`, passed.

## CI triage for run 34300098985

The source changes in this PR are limited to pkg/logservice. In the
exact-head CI run:

- Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed.
- The UT coverage producer failed only at the unrelated existing test
pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful,
which returned context canceled; the producer report recorded no build
failures and two failed events in pkg/sql/compile.
- The downstream coverage merge failed because the required UT producer
artifact was incomplete (prerequisites_ready=false); it did not
calculate a coverage verdict.
- The same TestIssue27261 test passed locally 10 times, and the PR
retry/close focused tests passed locally 20 times normally and 100 times
under -race; go vet and git diff --check passed.

No unrelated compile/pipeline change is included to mask this flaky
coverage-only failure. This PR was not rebased and the existing PR base
was not changed.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28453)

## Summary

HAKeeper can report a failed MORPC transport generation as
`ErrBackendClosed` instead of EOF. The managed client previously reset
that generation but returned the error directly, so a transient
control-plane disconnect escaped as a SQL failure during
`TestIssue26640CrossAccountRestoreRebindsPrivileges`.

This change:

- retries the transport-generation errors (`ErrBackendClosed`,
connect/admission failures, connection reset) through the caller's
existing deadline;
- makes `managedHAKeeperClient.Close` terminal, prevents late failures
from recreating a transport, and makes concurrent `Close` calls join the
same cleanup result;
- consolidates the retry regressions into deterministic table-driven
tests, including deadline, business-error, in-flight-close, and
concurrent-close cases.

The retry is bounded by every public HAKeeper request context. An
allocation whose response is lost may consume an ID range, as the
existing EOF retry already did, but the server's monotonic allocator
prevents duplicate IDs from being returned.

## Root cause and scope

- matrixorigin#28443 failed before its restore/privilege assertions. The embedded
LogService first reported checker/raft timing pressure, then MORPC
returned `backend connection closed` while allocating an ID. The failure
was a downstream control-plane transport error; the deeper first
scheduler/WAL/IO fault is not proven by that job.
- matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already
fixed by merged matrixorigin#28358, which is in this branch's base. The exact
regression test passes repeatedly on current main, so this PR
intentionally does not duplicate that dispatch implementation.

Fixes matrixorigin#28452

Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358

## Validation

- `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`,
passed.
- `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed.
- HAKeeper retry/close focused tests: normal and `-race -count=100`,
passed.
- `pkg/logservice`: normal and race package runs passed with the known
unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure`
excluded; that test still fails independently with listener address
collisions/store-close leakage.
- `go vet ./pkg/logservice` with the repository CGo flags and `git diff
--check`, passed.

## CI triage for run 34300098985

The source changes in this PR are limited to pkg/logservice. In the
exact-head CI run:

- Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed.
- The UT coverage producer failed only at the unrelated existing test
pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful,
which returned context canceled; the producer report recorded no build
failures and two failed events in pkg/sql/compile.
- The downstream coverage merge failed because the required UT producer
artifact was incomplete (prerequisites_ready=false); it did not
calculate a coverage verdict.
- The same TestIssue27261 test passed locally 10 times, and the PR
retry/close focused tests passed locally 20 times normally and 100 times
under -race; go vet and git diff --check passed.

No unrelated compile/pipeline change is included to mask this flaky
coverage-only failure. This PR was not rebased and the existing PR base
was not changed.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] HAKeeper client leaks transient backend closure into embedded UT SQL

2 participants