Repository navigation
fix(logservice): isolate HAKeeper client from caller timeout - #25869
mergify[bot] merged 4 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Completed a first-principles pre-push review of the complete PR diff at Scope and semantic boundary
Error-path review
Concurrency and lifecycle review
Validation
Remote verification:
No blocking correctness, leak, hang, ownership, retry-regression, cache-corruption, or unintended cross-module semantic issue found. Full GitHub CI is still in progress. |
|
Queued — the merge queue status continues in this comment ↓. |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The timeout-isolation change is incomplete for MORPC send-stage context failures and also introduces response-pool churn for late replies.
P1 - Clean up futures when Send returns a caller context error (pkg/logservice/hakeeper_client.go:920)
This predicate skips client reset for errors from both c.client.Send and future.Get. In MORPC, Send creates and inserts a Future before attempting to enqueue it. If the write queue is full and the caller context expires, doSend returns the context error before enqueueing; remoteBackend.send only calls f.Close, without messageSent/unRef. Because Future.Close releases only after its reference reaches zero, the Future remains in the backend's futures map and retains the request. Keeping the shared client alive means repeated admission-time cancellations can grow this map and memory without bound. The new test stubs the send function and does not exercise this path. The reset exemption must distinguish send-stage failures, or MORPC must release the Future on this path.
P2 - Recycle orphan responses when retaining timed-out clients (pkg/logservice/hakeeper_client.go:920)
Once the client is retained after a caller timeout, late HAKeeper replies can reach MORPC's orphan-response path. getRPCClient enables payload responses but does not configure WithBackendFreeOrphansResponse; MORPC therefore does not call RPCResponse.Release() for these late replies. Under repeated timeouts this bypasses the response pool and causes avoidable allocations and GC pressure. Configure the orphan-response release callback when constructing this client.
|
Addressed both findings from review P1 — pre-enqueue Future retentionConfirmed. Added a deterministic full-queue/canceled-context regression test. It fails before the fix with one Future left in P2 — orphan payload-response recyclingConfirmed. Added focused callback coverage. Full Final safety review
The PR description has also been updated with the two lifecycle gaps, ownership boundaries, and complete validation record. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the current head ab3fdb94d4 from the transport, lifecycle, concurrency, failure-classification, and performance angles. No blocking issue found.
The previous findings are closed:
- A Future registered before queue admission now gets the matching send completion/unref only on synchronous
doSendfailure. Successfully queued Futures remain owned by the write loop, and the existing CAS prevents duplicate send completion. - Late payload responses with neither a Future nor a Stream now follow the existing
RPCResponse.Releasepool lifecycle. Normal response ownership is unchanged. - Caller
context.Canceledandcontext.DeadlineExceededno longer invalidate the shared managed HAKeeper client, while EOF, UnexpectedEOF, connection-close, NoHAKeeper, backend timeout, and other non-context errors preserve reset/reconnect behavior.
Focused regression tests passed repeatedly in normal and race modes; full MORPC normal/race passed; both modified packages build and vet cleanly; git diff --check is clean; GitHub CI is green. The change adds no success-path allocation or wait and only adds constant-time error-path cleanup/classification.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The timeout isolation and synchronous Future cleanup are sound, but payload-response recycling misses a timeout race.
P2 - Release responses discarded while the Future still exists (pkg/logservice/client.go:929)
This callback only handles the requestDone branch where no Future/Stream is found. If a response arrives after the caller context expires but before future.Close, requestDone still finds the Future and Future.done drops the response without invoking freeResponse. Conversely, if the response was queued just before cancellation, Future.Get may select ctx.Done and Future.Close drains it without calling RPCResponse.Release. Retaining the shared client makes these late-response races reachable, so repeated timeouts bypass respPool and increase allocation/GC pressure.
…rigin#25869) Managed HAKeeper operations share one MORPC client. Before this change, every request error reset and closed that shared client, including `context.Canceled` and `context.DeadlineExceeded` from one caller. In TKE mergerun job 88168675381, a connection-ID allocation reached its frontend deadline and closed the established HAKeeper connection. Unrelated connection admission, CN heartbeat, task service, and cluster refresh requests were then forced through synchronous HAKeeper rediscovery. The SSB `q1.3` connection failed during that cascade even though HAKeeper recovered immediately and the next query succeeded. A caller context error means only that request can no longer wait; it does not establish that the shared transport is broken. MORPC's backend read loop independently detects EOF, connection errors, and read timeouts and reconnects the transport. This change: - returns caller cancellation/deadline errors unchanged without closing the shared HAKeeper client; - applies that rule consistently to all managed HAKeeper operations; - preserves existing reset/reconnect/retry behavior for EOF, connection-close, `NoHAKeeper`, backend timeout, and every other non-context error; - completes MORPC cleanup when `Send` fails before queue admission, so the Future is removed from the backend map instead of retaining its request indefinitely; - recycles payload-bearing logservice responses that arrive after their Future has already been removed; - does not change connection IDs, allocation batches, public APIs, configuration, timeouts, retry counts, or normal success paths. The regression coverage proves: - caller cancellation/deadline keeps the exact managed HAKeeper client reusable; - EOF send errors still reset, rebuild, and retry the client; - an admission-stage context error leaves no Future in MORPC's backend map (the test fails on unmodified code with one retained Future); - the orphan-response callback releases the `RPCResponse` payload back through its existing pool lifecycle. Approved by: @volgariver6, @gouhongshen, @XuPeng-SH
…rigin#25869) Managed HAKeeper operations share one MORPC client. Before this change, every request error reset and closed that shared client, including `context.Canceled` and `context.DeadlineExceeded` from one caller. In TKE mergerun job 88168675381, a connection-ID allocation reached its frontend deadline and closed the established HAKeeper connection. Unrelated connection admission, CN heartbeat, task service, and cluster refresh requests were then forced through synchronous HAKeeper rediscovery. The SSB `q1.3` connection failed during that cascade even though HAKeeper recovered immediately and the next query succeeded. A caller context error means only that request can no longer wait; it does not establish that the shared transport is broken. MORPC's backend read loop independently detects EOF, connection errors, and read timeouts and reconnects the transport. This change: - returns caller cancellation/deadline errors unchanged without closing the shared HAKeeper client; - applies that rule consistently to all managed HAKeeper operations; - preserves existing reset/reconnect/retry behavior for EOF, connection-close, `NoHAKeeper`, backend timeout, and every other non-context error; - completes MORPC cleanup when `Send` fails before queue admission, so the Future is removed from the backend map instead of retaining its request indefinitely; - recycles payload-bearing logservice responses that arrive after their Future has already been removed; - does not change connection IDs, allocation batches, public APIs, configuration, timeouts, retry counts, or normal success paths. The regression coverage proves: - caller cancellation/deadline keeps the exact managed HAKeeper client reusable; - EOF send errors still reset, rebuild, and retry the client; - an admission-stage context error leaves no Future in MORPC's backend map (the test fails on unmodified code with one retained Future); - the orphan-response callback releases the `RPCResponse` payload back through its existing pool lifecycle. Approved by: @volgariver6, @gouhongshen, @XuPeng-SH
…rigin#25869) Managed HAKeeper operations share one MORPC client. Before this change, every request error reset and closed that shared client, including `context.Canceled` and `context.DeadlineExceeded` from one caller. In TKE mergerun job 88168675381, a connection-ID allocation reached its frontend deadline and closed the established HAKeeper connection. Unrelated connection admission, CN heartbeat, task service, and cluster refresh requests were then forced through synchronous HAKeeper rediscovery. The SSB `q1.3` connection failed during that cascade even though HAKeeper recovered immediately and the next query succeeded. A caller context error means only that request can no longer wait; it does not establish that the shared transport is broken. MORPC's backend read loop independently detects EOF, connection errors, and read timeouts and reconnects the transport. This change: - returns caller cancellation/deadline errors unchanged without closing the shared HAKeeper client; - applies that rule consistently to all managed HAKeeper operations; - preserves existing reset/reconnect/retry behavior for EOF, connection-close, `NoHAKeeper`, backend timeout, and every other non-context error; - completes MORPC cleanup when `Send` fails before queue admission, so the Future is removed from the backend map instead of retaining its request indefinitely; - recycles payload-bearing logservice responses that arrive after their Future has already been removed; - does not change connection IDs, allocation batches, public APIs, configuration, timeouts, retry counts, or normal success paths. The regression coverage proves: - caller cancellation/deadline keeps the exact managed HAKeeper client reusable; - EOF send errors still reset, rebuild, and retry the client; - an admission-stage context error leaves no Future in MORPC's backend map (the test fails on unmodified code with one retained Future); - the orphan-response callback releases the `RPCResponse` payload back through its existing pool lifecycle. Approved by: @volgariver6, @gouhongshen, @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
issue #25868
What this PR does / why we need it:
Managed HAKeeper operations share one MORPC client. Before this change, every request error reset and closed that shared client, including
context.Canceledandcontext.DeadlineExceededfrom one caller.In TKE mergerun job 88168675381, a connection-ID allocation reached its frontend deadline and closed the established HAKeeper connection. Unrelated connection admission, CN heartbeat, task service, and cluster refresh requests were then forced through synchronous HAKeeper rediscovery. The SSB
q1.3connection failed during that cascade even though HAKeeper recovered immediately and the next query succeeded.A caller context error means only that request can no longer wait; it does not establish that the shared transport is broken. MORPC's backend read loop independently detects EOF, connection errors, and read timeouts and reconnects the transport.
This change:
NoHAKeeper, backend timeout, and every other non-context error;Sendfails before queue admission, so the Future is removed from the backend map instead of retaining its request indefinitely;The regression coverage proves:
RPCResponsepayload back through its existing pool lifecycle.Review follow-up and safety boundary
The requested review at
pullrequestreview-4730633356identified two valid lifecycle gaps. Commitab3fdb94d4addresses both with focused cleanup changes:doSend. If enqueue fails, no write-loop owner exists, so the synchronous send-error path now performs the single matching send-completion/unref before closing it.WithBackendFreeOrphansResponseand the existingRPCResponse.Releaseimplementation.Normal queued sends are unchanged: only the write loop calls send completion. Normal responses are unchanged: the caller still owns
RPCResponse.Release. The orphan callback runs only when MORPC finds neither a Future nor a Stream, so it does not overlap normal response ownership.Testing
Tested with MatrixOne macOS CGo header/link settings:
go test ./pkg/common/morpc -run '^TestSendContextErrorReleasesFuture$' -count=20go test -race ./pkg/common/morpc -run '^TestSendContextErrorReleasesFuture$' -count=20count=10, racecount=10go test ./pkg/common/morpc -count=1go test -race ./pkg/common/morpc -count=1go test ./pkg/logservice -count=1go test -race ./pkg/logservice -count=1go test ./pkg/frontend ./pkg/cnservice ./pkg/proxy -run '^$' -count=1go build ./pkg/common/morpc ./pkg/logservice ./pkg/frontend ./pkg/cnservice ./pkg/proxygo vet ./pkg/common/morpc ./pkg/logservicegit diff --check