Skip to content

fix: eliminate reconnect and checkpoint timeout flakes - #26011

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
XuPeng-SH:fix_26008_25997_ci_timeouts
Jul 22, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
XuPeng-SH:fix_26008_25997_ci_timeouts

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #26008
Fixes #25997

What this PR does / why we need it:

TestSpeedupAbortAllTxn exposed a MORPC lifecycle failure, not merely a slow test. A closed backend could remain counted against maxBackendsPerHost, reconnect could keep selecting terminal capacity, failed locked stream creation could leak the backend lock, and Stream.Close/backend shutdown did not give an already-blocked receiver a reliable terminal event. Cleanup was then made asynchronous, but a deeper review found that concurrent Close callers, targeted reset, and in-flight factory creation were not all part of the same completion boundary.

This PR makes the lifecycle explicit and joinable:

  • operation-level backend-closed errors retire the exact backend immediately;
  • inactive/idle entries are detached only after bounded cleanup ownership is admitted, preserving the pool resource bound under saturation;
  • healthy selection keeps its single-scan fast path;
  • failed locked NewStream returns lock ownership to the client;
  • remoteBackend.Close distinguishes sealed admission (stateStopped) from completed physical teardown (closeDone), so every concurrent caller joins the same owner;
  • backend shutdown terminates active streams before waiting for transport workers, and both Stream.Close modes publish a nil terminal to an existing receiver;
  • terminal streams reject sends, receives, and late responses; failed terminal sends no longer refresh backend activity;
  • a full write-queue waiter also observes backend stop, breaking the stream-lock/transport-stop wait cycle;
  • client Close joins detached cleanup, concurrent targeted reset, and every factory create admitted before closing, so its return is a real lifecycle postcondition;
  • compacted slice tails are cleared so retired backend object graphs are not retained.

The backup protection failures had a separate test-contract bug. They used a five-second force-checkpoint helper and then polled runner/WAL idleness, which is neither the required checkpoint-coverage postcondition nor a stable ordering guarantee under CI contention. The tests now call the context-aware ForceCheckpoint with a bounded 30-second deadline and assert that the completed incremental checkpoint covers the requested timestamp.

Review decisions

  • closeConn controls only whether the shared transport is also closed; local stream closure always terminates an already-obtained receive channel.
  • Stream termination snapshots activeStreams under the backend mutex and enters stream state only after releasing it, preserving the lock order used by unregister.
  • Foreground recovery never waits for slow backend teardown. Cleanup is capped at 64 concurrent owners; when saturated, a terminal backend remains counted against capacity until cleanup can be admitted.
  • CloseBackendFor remains responsive to unrelated in-flight factory I/O, but its own detached teardown is registered so a concurrent total client Close can join it.
  • The checkpoint timeout remains bounded and inherits the test context. No production checkpoint, GC-scan, or WAL publication ordering is changed by this PR.

Validation on latest main (e6f5587c):

  • focused MORPC close/stream/create/reset unhappy paths: -race -count=100
  • full pkg/common/morpc: -race -count=1
  • full pkg/txn/rpc: -race -count=1
  • TestSpeedupAbortAllTxn: -race -count=1 on the final tree (and -count=5 before the final lifecycle extension)
  • full pkg/backup: -race -count=1
  • backup protection regressions: -count=10
  • TestSnapshotMeta: -count=50
  • healthy backend lookup benchmark: 159-194 ns/op, 128 B/op, 1 alloc/op
  • go build for MORPC and backup
  • go vet for MORPC, backup, and issue tests
  • git diff --check

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Jul 22, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 22, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Jul 22, 2026

@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.

BLOCKING deep-review result: one lifecycle issue must be fixed before this PR leaves draft. I verified the final merge resolution, stream lock ordering and generation isolation, backend terminal-state closure, inactive-pool compaction, and the stronger backup checkpoint postcondition. The morpc package, focused lifecycle tests under race (-count=5), affected backup tests, and go vet all pass, but the operation deadline can still be lost while retiring a closed backend. GitHub does not permit the PR author account to submit REQUEST_CHANGES on its own PR, so this is filed as a blocking COMMENT review.

Comment thread pkg/common/morpc/client.go Resolved
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Jul 22, 2026
@XuPeng-SH
XuPeng-SH force-pushed the fix_26008_25997_ci_timeouts branch from 78688c0 to 227977e Compare July 22, 2026 11:03
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Jul 22, 2026

@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 re-review of exact head 227977ec4e0a72b91a24ff9f0a4172833b3808c9: no blocking findings.

I revalidated the previous P1 and the subsequent lifecycle hardening end to end:

  • Send, Ping, and NewStream detach only the exact failed backend and never wait for Backend.Close on the foreground RPC path. Cleanup ownership is transferred before pool capacity is released, is capped at 64 per client, and saturation keeps terminal backends consuming capacity instead of allowing unbounded goroutine/backend churn.
  • Client.Close seals create/cleanup admission, invalidates queued generations, snapshots the pool, and joins retired cleanup, targeted reset, and admitted factory I/O. Backend generation identity prevents stale publication/ABA, and compacted slice tails are cleared.
  • remoteBackend.Close has a terminal admission seal plus a completion barrier, concurrent callers join physical teardown, write-queue waiters observe shutdown, active streams terminate before transport teardown, and stopped backends cannot be reactivated.
  • Stream terminal/close paths reject late send/receive/delivery, publish exactly one usable terminal notification to a previously acquired receive channel, and avoid the rb.mu/s.mu inverse lock order.
  • The backup tests now wait on the real ForceCheckpoint(ctx, target) postcondition and assert the resulting ICKP covers target; they no longer depend on a weaker fixed-delay idle poll.

Validation on this exact head:

  • focused lifecycle/concurrency tests: go test -race -count=20 ./pkg/common/morpc -run <19 changed lifecycle tests>
  • full package: go test -race ./pkg/common/morpc
  • backup protection tests: go test -count=3 ./pkg/backup -run 'TestBackupProtection(...)'
  • backup protection race run: go test -race ./pkg/backup -run 'TestBackupProtection(...)'
  • go vet ./pkg/common/morpc ./pkg/backup

All passed. The remaining no-context nature of BackendFactory.Create/Backend.Close means an explicit total Client.Close can still wait on a stuck implementation; that is the existing synchronous destruction contract, while the operation path is now bounded and non-blocking with respect to cleanup.

GitHub does not allow the PR author account to approve its own PR, so this formal COMMENT review records a code-review pass rather than APPROVE.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

@LeftHandCold please help to review

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex automated review

No actionable regressions found. The prior blocking teardown-latency finding is fixed, lifecycle closure is consistent across retirement, creation, reset, concurrent close, and stream termination, and checkpoint tests now assert the required coverage postcondition. Current-head CI is green.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deep review completed on exact head 50d404c. No blocking findings.

I traced the MORPC backend/client/stream lifecycle end to end: exact-backend retirement, bounded asynchronous cleanup ownership, concurrent Client.Close and targeted reset, in-flight factory generation admission, remoteBackend teardown joining, stream terminal delivery and lock ordering, write-queue shutdown, activity-state publication, and slice-tail reference release. The cleanup/wait/growth invariants are closed without changing the healthy backend selection behavior. I also verified the backup test change waits for the actual ForceCheckpoint coverage postcondition and does not alter production checkpoint/WAL/GC ordering.

Fresh validation on this head passed: focused MORPC lifecycle tests under -race -count=10; full pkg/common/morpc under -race; full pkg/backup under -race; backup protection tests -count=3; TestSpeedupAbortAllTxn under -race; go vet for MORPC, backup, and issue tests; go build for MORPC and backup; git diff --check.

@mergify

mergify Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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

kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UT TestSpeedupAbortAllTxn times out after logtail reconnect [Bug]: CI UT timeout failures in transaction abort and backup protection tests

4 participants