Repository navigation
fix(cnservice): return bootstrap failures - #26503
Conversation
PR Summary by Qodofix(cnservice): return bootstrap failures instead of panicking
AI Description
Diagram
High-Level Assessment
Files changed (20)
|
Code Review by Qodo
1. Cancel executed under mutex
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review on 53de8f3c39f20da8d23f0549e6e808dc530bcbe9 found two lifecycle blockers.\n\n1. Bootstrap is retired while frontend consumers are still live. service.Close invokes closeBootstrapService before stopFrontend, and closeBootstrapService sets s.bootstrapService = nil before calling Close. At the same time active/new frontend sessions call GetFinalVersion, CheckTenantUpgrade, and UpgradeTenant through BaseService, all of which dereference s.bootstrapService without synchronization. A concrete shutdown interleaving is: Close stores nil -> an authentication/upgrade request enters before the SQL listener/session is stopped -> GetFinalVersion invokes a method on the nil interface and panics (and the field read/write is itself a race). Simply moving the step may still be insufficient if frontend stop closes sessions without joining their handlers; the bootstrap generation must remain stable until every consumer is drained, or access/retirement must be synchronized. Please add a deterministic barrier-based close-vs-upgrade/auth regression.\n\n2. The new returned Start error is not cleanup-safe for all CN owners. The embedded operator now transfers ownership before Start, but pkg/tests/service.(*cnService).Start leaves status as ServiceInitialized on error while its Close only closes ServiceStarted. Therefore the exact bootstrap reset now returned by this PR leaves the constructor-opened SQL listener plus bootstrap-created incr/trace services and clients alive; a later cluster Close is a no-op for that CN. cmd/mo-service.startCNService also panics on s.Start() without first closing the constructed service. Please close the ownership loop for every direct cnservice.NewService caller (or make failed Start transactionally roll itself back), and test failure -> cleanup -> SQL address reuse/runtime globals removed.\n\nThe MORPC cache callback-outside-lock change and pipeline closing + WaitGroup admission boundary look correct; focused CN/MORPC lifecycle tests passed under race locally. While adding the missing regressions, please replace the 2.2s sleep in TestFragmentedPipelineCacheSurvivesHandlerRelease with an observable scan/barrier: elapsed time does not prove that either cleanup scan actually ran under CI scheduling.
XuPeng-SH
left a comment
There was a problem hiding this comment.
One lifecycle blocker remains at service.Start / service.Close:
Start rolls a failed attempt back through s.Close(), which permanently consumes closeOnce, but Start has no state/admission guard. A caller that retries the now-returned bootstrap error creates and publishes a new auto-increment service and txn-trace service; when that second attempt fails, the deferred Close is a no-op, so the new goroutines/runtime globals remain live and every later Close is also unable to reclaim them. The Service interface does not document a single-call-only contract or reject a start on a closed instance. The same missing state boundary also permits teardown and publication to overlap if Start and Close race.
I reproduced the sequential case on exact head ac5a2b391f2a1c1653c066d0e4cb69735858b5a6 with a real Start -> bootstrap error -> Start -> bootstrap error counterexample: runtime.AutoIncrementService was still present after the second return (the test failed in 0.05s). Please add an explicit one-shot lifecycle state gate (or make retries transactionally safe), and keep this counterexample as a deterministic regression test.
The previous listener/global cleanup, bootstrap-consumer synchronization, fragmented-cache ownership, cancellation-outside-lock, and trace-producer ordering issues are otherwise closed. The new targeted CN/MORPC/frontend/runtime tests pass locally under -race, and all current CI checks are green.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on af1b2f8. The previous lifecycle blockers are resolved and I found no new merge blocker.
The one-shot Start/Close state gate now makes failed startup cleanup terminal and rejects reuse after close; bootstrap consumers remain protected until retirement; pipeline admission, cancellation, handler draining, trace shutdown, and fragmented-message cancel ownership form a complete shutdown closure. Runtime cleanup is generation-safe through CompareAndDelete, and retained handler/cache state is bounded and reclaimed on completion, timeout, or session close.
Fresh local validation passed: adaptive focused race stress for all changed lifecycle transitions, Test_TxnExecutorExec under race with count=2, full race runs for cnservice, morpc, frontend, runtime, and txnexecutor, plus build and vet for the production packages.
Merge Queue Status
This pull request spent 12 seconds in the queue, including 1 second running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #26489
What this PR does / why we need it:
CN bootstrap previously panicked for every failure except
context.Canceled.A transient HAKeeper connection reset therefore terminated the test process.
Returning the error safely requires complete lifecycle ownership. Bootstrap
must run after the embed operator owns the CN; constructor-opened SQL listeners
and bootstrap-created runtime services must be closed on rollback; and trace
consumers must remain alive until every producer has stopped.
This change:
Service.Start()after operator ownership transfer;MOServer.Start()was never called;generation-safe runtime cleanup;
requests already read by a goetty session when shutdown starts;
cancels all of them before waiting during shutdown;
releases every transferred fragment context on assembly, timeout, or session close;
trace; and
producer before the trace consumer.
Validation:
real RPC admission-race tests passed 100 times
assembles all fragments
fragment contexts exactly once
pkg/common/morpcandpkg/cnservicetests passedpkg/frontendand runtime tests, plus embedded rollback tests, passedhandleRequest, 88.9% for fragment handling,and 85.7% for cancelable cache creation