Skip to content

fix(service): shut down standalone services in dependency order - #28015

Merged
XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27945-standalone-shutdown-order
Sep 7, 2026
Merged

XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27945-standalone-shutdown-order

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #27945

What this PR does / why we need it:

Problem

Standalone clean restart must stop every owned dynamic CN child before the parent exits, must not advance the supervisor after a configured Proxy shutdown failure, and must keep the Python UDF provider alive until CN consumers have drained.

Changes

  • Make dynamic-CN shutdown fail-closed. After the deadline, every still-owned child is escalated to SIGKILL, all kill/reap results are drained, and a final ownership check rejects any remaining child PID. A SIGTERM error also escalates immediately instead of allowing the child to survive the parent.
  • Propagate a configured Proxy Close() error as the supervisor terminal error, so the CN phase is not entered after Proxy shutdown fails.
  • Order the standalone phases as Proxy -> CN -> Python -> TN -> Log, preserving the Python provider through CN completion and covering the barrier with a deterministic regression.
  • Keep shutdown/restart admission guarded while stopping and clear only matching reaped child ownership slots.
  • Remove the ineffective break reported by golangci-lint SA4011 in the dynamic-CN shutdown deadline branch.

Compatibility and non-goals

The existing graceful shutdown, cancellation, and restart semantics remain unchanged for successful paths. This change only makes terminal failure and provider-ordering contracts explicit; it does not alter SQL behavior or issue metadata.

Validation

  • Exact envelope: base main at 99ed717b769e261b842c2f17345bd65865fc1470; source head 197be8c27524483c5b1eebbed7aadd9d60ee800d; clean semantic-preflight diff SHA-256 825ca3bbfb5d0d44f9d9d8e3af32c2ef26d7ad9cc1821bfc0d4133edbde3221e.
  • Semantic preflight and complete self-review: PASS, including the dynamic-CN fail-stop/reap/ownership contract, Proxy terminal-error propagation, and CN-before-Python provider barrier.
  • go list -mod=readonly for cmd/mo-service, pkg/cnservice, and pkg/common/chaos: PASS.
  • pkg/common/chaos unit tests, build, and vet: PASS.
  • Four exact chaos lifecycle regressions under -race -count=100, plus one full owning-package race run: PASS.
  • Formatting and git diff --check: PASS.
  • cmd/mo-service and pkg/cnservice focused CGo tests: blocked_external before test compilation because the worktree lacks cgo/libmo.dylib; no unbounded native build was started and no local CGo PASS is claimed.
  • BVT: N/A. SQL BVT cannot deterministically send process signals, assert child reap/ownership, or observe the cross-role Proxy/CN/Python phase barrier; equivalent deterministic Go regressions cover those contracts.
  • The previous exact-head run 34007471347 had the independent Linux/arm64 SCA SA4011 failure at cmd/mo-service/dynamic.go:461; this new head contains the one-line fix. Fresh CI checks for 197be8c27524483c5b1eebbed7aadd9d60ee800d are pending, so CI is not claimed green.

QA decision

QA required: yes

QA should validate the exact head with the standalone production entrypoint: graceful shutdown, dynamic-CN timeout and SIGTERM-failure escalation with no alive owned child, configured Proxy Close() failure with CN unopened, and the CN-before-Python provider barrier. Verify the same UUID/data restart and HAKeeper view/metadata admission after shutdown. Automated terminal coverage is included above; deployed/manual lifecycle validation remains required.

This PR remains Ready for review.

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Sep 2, 2026
@mergify mergify Bot added kind/bug Something isn't working kind/refactor Code refactor labels Sep 2, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/issue-27945-standalone-shutdown-order branch from 4d0dc9c to 104e5b3 Compare September 2, 2026 12:20
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

mo-55 E2E 已完成(验证 head 104e5b3c5e26e2722c05c532225c0f3d84e14f5e;当前仅有 unused-helper 清理提交 e8956eb9828f05ebd264e6e7272c88dfcbb1122d)。

  • self-contained post-fix template,UUID/data path/ports 已核对;共享服务未触碰。
  • 默认 30s discovery timeout 下 same-UUID graceful restart 10/10 PASS;SQL ready 5–7s,shutdown 1–2s,0 admission timeout/panic/hang。
  • cycle 1/5/10 日志确认 CN withdrawal → TN → LogService/HAKeeper 的关闭顺序;FULLTEXT2 digest 3/3 一致。
  • disposable clone 的 SIGKILL fence PASS:replacement 37s ready,未提前接管(<15s 为 false),90s 内恢复,行数 2,303,643。
  • 旧 template 首次启动需要 legacy wait,整体状态 PASS_WITH_LEGACY_LIMITATION;路径错误的早期尝试已排除,不作为证据。

证据 manifest:82e20c9f3824de3971acbcedeb9d39e32ecdf369f7b97d977d895f91206572a,目录位于 mo-55 /home/sunyuze/fulltext2-pr27955-validation-c46d897e-20260902/results/pr27955-pr-a-e2e-20260903/。性能统一标记 PERF_INCONCLUSIVE_HOST_BUSY;#27945 保持 OPEN,当前 PR 仍 Draft,等待 exact current head CI、设计审查和 QA terminal PASS。

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

Deep review of exact head f88c875cdf1202d1399760c8da8f6fcd6e09731e against base 99ed717b769e261b842c2f17345bd65865fc1470: REQUEST_CHANGES.

The role-ordering direction is sound, the ordinary same-UUID restart evidence is useful, and the partial-startup/proxy publication repairs are consistent. One lifecycle counterexample remains blocking.

P1 — Dynamic CN can be restarted after the graceful-shutdown PID snapshot and survive the parent

stopAllDynamicCNServicesGracefully snapshots dynamicCNServicePIDs before it calls ChaosTester.Stop(). The HTTP control handler remains active, and startDynamicCNByIndex has no stopping/generation gate.

Concrete interleavings:

  1. Chaos has killed slot 0, so the shutdown snapshot records PID 0; its already-running restart callback then starts PID 101 before ChaosTester.Stop returns.
  2. The snapshot records PID 100; an HTTP stop/then start replaces it with PID 101 while shutdown is stopping/waiting PID 100.

In both cases PID 101 is absent from the immutable snapshot and receives no SIGTERM. Because dynamic children use Setsid, the new process can survive the parent exit, retain ports/state, and break the next same-data/same-UUID startup. The compare-before-zero logic only prevents clearing a newer PID; it does not terminate that newer PID. This violates the PR's central invariant that all CN ingress/children are closed before TN and LogService.

Please make shutdown an atomic lifecycle transition under the same ownership lock: mark the dynamic manager stopping first, reject HTTP/chaos starts and restarts after that point, quiesce and wait for chaos callbacks/control ingress, and only then snapshot/terminate the final child set. Add deterministic tests for both a restart callback and an HTTP start racing graceful shutdown, asserting no child remains and no new fork occurs after the stopping transition.

I also checked the exact-head CI and focused pkg/common/chaos tests (PASS). The local cmd/mo-service focused binary could not start because this machine has no libmo.dylib; that environment limitation does not affect the source-level counterexample above.

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

Deep review of exact head f88c875 against base 99ed717: REQUEST_CHANGES.

I reviewed the design contract, the complete 11-file diff, lifecycle ownership/order, startup cleanup, CN withdrawal, chaos shutdown, tests, and exact-head CI. The dependency-order direction is sound, but the dynamic-CN shutdown still has a blocking producer-versus-snapshot race.

I reproduced it with a deterministic temporary test at the exact head: start with slot PID 100, let graceful shutdown snapshot it, replace the slot with PID 101 while PID 100 is being signaled, and let the old wait complete. stopAllDynamicCNServicesGracefully returned nil while dynamicCNServicePIDs[0] remained 101 (expected 0). The focused CGo test failed exactly on that assertion; the temporary test was then removed. Exact-head CI is green, but it does not exercise this interleaving.

Comment thread cmd/mo-service/dynamic.go Resolved
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the dynamic-CN shutdown race raised in review. stopAllDynamicCNServicesGracefully now publishes the stopping state before quiescing chaos, detaches the tester, takes the PID snapshot only after Stop returns, and terminates/waits on that final set. Direct HTTP starts and the exact chaos RestartFunc are rejected after stopping begins. Added deterministic regressions for final-PID replacement, HTTP start, and chaos restart.\n\nExact head 95a81aa2cf2c908280d48ffd6a082409c4f5ed6a: semantic preflight PASS, pkg/common/chaos test PASS, formatting and diff checks PASS. The focused cmd/mo-service CGo test is blocked before compilation because this isolated worktree lacks cgo/libmo.dylib; fresh CI and exact-head QA remain pending.

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

Deep review of exact head 95a81aa2cf2c908280d48ffd6a082409c4f5ed6a against base 99ed717b769e261b842c2f17345bd65865fc1470: REQUEST_CHANGES.

The previous producer-versus-PID-snapshot race is fixed: stopping is now published before chaos is quiesced, the final PID snapshot is taken afterwards, and HTTP/chaos restarts are rejected. Exact-head CI is green. Three lifecycle counterexamples remain:

P1 — A timed-out dynamic CN can survive the standalone parent

Dynamic children are deliberately started in a new session with Setsid: true (dynamic.go#L357-L366). Graceful shutdown sends SIGTERM and waits, but when the one-minute CN phase context expires it returns immediately without SIGKILL or a terminal reap of the remaining children (dynamic.go#L395-L423, lifecycle.go#L192-L210). The main path then returns the shutdown error and exits without invoking the global stopper.

Concrete path: a dynamic CN is stuck in its own shutdown -> the supervisor reaches its one-minute deadline -> the parent exits non-zero -> the independent-session child remains alive, retaining its ports and data directory -> the next same-data/same-UUID startup can collide with the orphan. The current context test explicitly lets the wait remain blocked until the test releases it after the shutdown function has already returned, so it does not prove process-tree termination.

Please add a fail-stop fallback after the graceful deadline: SIGKILL every still-owned child and reap/verify the final child set before the parent leaves. Add a deterministic timeout test whose oracle is that no dynamic child remains alive/owned after return.

P1 — A configured proxy Close failure is reported as a clean phase

pkg/proxy.Server.Close returns the ingress application's Stop error (server.go#L329-L357), but runProxyServerUntilCanceled only logs that error and always returns nil after cancellation (main.go#L541-L555). Consequently the proxy task calls finish(nil), and the supervisor advances to CN teardown even though proxy ingress closure is unknown. That directly violates the design's “an error stops transition” rule and can admit work while its CN dependency is being removed.

Please propagate the Close error into the role's terminal result (without turning it into an unrecorded goroutine panic), and add a test showing that a configured-proxy Close error keeps the CN phase unopened.

P2 — Python UDF is closed before its CN consumer

The phase order is currently proxy -> Python -> CN (lifecycle.go#L188-L197). However Python UDF is a provider used by CN: CN installs the Python client into UdfService (server.go#L238-L269), and query execution calls it with the CN process context (python_udf.go#L108-L116). Closing the Python role kills that process before CN has stopped frontend/query ingress, so an already accepted or direct-CN UDF request loses its provider during “graceful” shutdown.

Please derive the order from the consumer graph: stop/drain CN before Python, and test that the Python provider remains available until the CN phase has completed.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the three current lifecycle findings in exact head 6cd70996d6d40caf4fde946091d6228aad8251b5 (base main, 99ed717b769e261b842c2f17345bd65865fc1470).

  1. Dynamic CN timeout and SIGTERM failure

stopAllDynamicCNServicesGracefully now fail-stops every still-owned child after the deadline: it sends SIGKILL, drains all kill/reap results, and performs a final ownership verification before returning. If SIGTERM itself fails, that child is escalated to SIGKILL immediately. Matching successful reap results clear only the matching PID slot; any remaining ownership is returned as a terminal error. Covered by TestStopAllDynamicCNServicesForceStopsAfterDeadline, TestStopAllDynamicCNServicesEscalatesAfterSIGTERMFailure, and the deterministic context/reap regression.

  1. Configured Proxy Close() error

runProxyServerUntilCanceled now propagates a configured Proxy Close() failure through its named return value. startProxyService records that role terminal error, so the supervisor stops before entering the CN phase. Covered by TestServiceSupervisorConfiguredProxyFailureStopsBeforeCN.

  1. Python UDF provider ordering

The standalone phase order is now Proxy -> CN -> Python -> TN -> Log. The Python provider remains alive until CN consumers finish, with a barrier/order regression in TestServiceSupervisorKeepsPythonProviderUntilCNDrains.

Local semantic preflight and the complete self-review are PASS. The owning pkg/common/chaos unit/build/vet checks and race stress runs are PASS. The focused cmd/mo-service CGo tests remain blocked_external before compilation because this worktree lacks cgo/libmo.dylib; no local CGo PASS is claimed. Fresh CI checks for this exact head are in progress.

QA required: yes. Please re-review the exact head.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

@XuPeng-SH Rechecked the three lifecycle blockers against the new exact head 197be8c27524483c5b1eebbed7aadd9d60ee800d.

  • Dynamic CN shutdown marks the manager stopping before the final PID snapshot, rejects HTTP/chaos restarts, escalates each still-owned child from SIGTERM to SIGKILL after the phase deadline or TERM failure, drains Wait, and rejects any remaining owned PID.
  • A configured Proxy Close() error is joined into the proxy role result and stops the supervisor before the CN phase.
  • The shutdown phases are Proxy -> CN -> Python -> TN -> Log, with a deterministic CN-before-Python barrier regression.
  • The ineffective break reported by Linux/arm64 SCA SA4011 on the previous head was removed.

Validation: semantic preflight PASS; complete self-review PASS; pkg/common/chaos normal/race/build/vet PASS; four exact chaos lifecycle tests passed at -race -count=100; the full pkg/common/chaos race package passed; git diff --check PASS. The cmd/mo-service and pkg/cnservice CGo-focused tests are blocked before compilation by the missing cgo/libmo.dylib, with no local CGo PASS claimed. BVT is N/A because these process/role terminal contracts are covered by deterministic Go production-path regressions. Fresh CI for this head is running, including SCA; it is not yet claimed green. Please re-review when convenient.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

@aptend Rechecked the dynamic shutdown race and the three current lifecycle blockers against the new exact head 197be8c27524483c5b1eebbed7aadd9d60ee800d.

  • The manager is marked stopping before the final PID snapshot, and both HTTP start and chaos restart are rejected during shutdown; each owned child is escalated to SIGKILL after the deadline or a SIGTERM failure, then waited/reaped with a final ownership assertion.
  • Configured Proxy Close() failures now propagate through the proxy role and prevent the CN phase from opening.
  • CN drains before Python UDF shutdown, covered by a deterministic barrier test.
  • The previous-head Linux/arm64 SCA SA4011 ineffective break was removed.

Validation: semantic preflight PASS; complete self-review PASS; pkg/common/chaos normal/race/build/vet PASS; four exact chaos lifecycle tests passed at -race -count=100; full owning-package race PASS; git diff --check PASS. CGo-focused tests for cmd/mo-service and pkg/cnservice are externally blocked before compilation by missing cgo/libmo.dylib; no local CGo PASS is claimed. BVT is N/A because deterministic Go regressions cover the process/role terminal contracts. Fresh checks for this head are running and CI is not yet claimed green. Please re-review when convenient.

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

Deep review of exact head 197be8c against merge-base 99ed717: REQUEST_CHANGES.

The previous three blockers are resolved: the dynamic-CN producer/snapshot race is closed, deadline and TERM-failure paths escalate and reap, configured Proxy Close errors stop before CN, and Python remains available until CN drains. Exact-head CI is green. Two lifecycle counterexamples remain.

P1 — Configured Proxy startup failures leave a live but unusable mo-service

At cmd/mo-service/main.go lines 610-620, both a runProxyServerUntilCanceled failure before shutdown and a permanent file-service initialization failure are copied into taskErr and the named task simply returns. finishTask stores that error, but the supervisor only reads it after waitSignalToStop receives an external signal or HAKeeper shutdown. startProxyService already returned success when the task was scheduled, so main can wait forever while the configured Proxy role is gone and the remaining standalone roles stay alive.

Concrete path: launch with -with-proxy; Proxy Start or permanent file-service initialization fails before roleCtx is canceled; proxy-service exits; no shutdown signal is produced; the process remains alive but the SQL ingress it advertises is unavailable. Before this PR these non-cancellation failures panicked and failed fast.

Please preserve a terminal startup/run failure path. Either notify main through a supervisor fatal channel and enter startup-failure cleanup, or distinguish a pre-cancellation error and retain the existing fail-fast behavior while continuing to record Close errors during controlled shutdown. Add a deterministic test proving a configured Proxy startup failure cannot leave main waiting for an unrelated signal.

P1 — Deadline escalation can signal a PID after that child was reaped

At cmd/mo-service/dynamic.go lines 400-459, dynamicWaitProcess reaps the child in a goroutine, but reaped and dynamicCNServicePIDs are updated only later when the result consumer runs. If the wait result and ctx.Done are both ready, select may choose the deadline branch. That branch still sees reaped false and the old PID in the slot, then calls raw syscall.Kill with SIGKILL. At minimum this can turn a clean exit at the deadline into a false ESRCH terminal failure; once Wait has reaped the child and the OS reuses the numeric PID, it can signal an unrelated process.

Please give each child one process identity and serialize Signal/Kill with Wait terminal state, for example by retaining and using the same os.Process handle instead of combining a separate Wait object with raw PID kills, or by an equivalent handshake that makes post-reap signaling impossible. Add a deterministic boundary test where Wait has completed before deadline escalation and assert that no SIGKILL is sent after reap.

Validation reviewed: full 13-file change map and lifecycle ownership/wait-for graph, exact-head Linux UT/SCA/Coverage/standalone and proxy BVT checks all green, pkg/common/chaos race stress PASS. Local CGo wrapper correctly rejected cross-worktree artifact reuse because native inputs differ; no local cmd/mo-service CGo PASS is claimed.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the current-head lifecycle findings in 29d7b90858d14e6c2018273f8d2e9f567a0a5561:

  • Configured proxy task failures now publish through the supervisor fatal channel and wake waitSignalToStop; fatal cleanup uses the same ordered role shutdown and dynamic-CN cleanup path.
  • Dynamic CN shutdown snapshots both PID and os.Process identity, clears a successfully reaped child before result consumption, and rechecks ownership before cancellation-driven SIGKILL.
  • Startup registers dynamic-CN cleanup before child launch, and restart/start requests are rejected after shutdown begins.
  • Added regressions for proxy failure wakeup, ordered cleanup, final PID snapshots, reaped-child cancellation, and stop-barrier behavior.

Validation: git diff --check and schema-v6 semantic preflight PASS. The local cmd/mo-service CGo test package remains blocked by the unavailable matching cgo/libmo.dylib prerequisite; no local test PASS is claimed for that package.

Please re-review this exact Ready head.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Follow-up on exact head 54051ca3e14562d872df660d28491fc569d6a006:

The prior Linux connector job exposed a portability compile failure in the new dynamic-process launch path: os.ProcAttr.Files was initialized with []uintptr, while the Linux API requires []*os.File. The source now passes os.Stdin, os.Stdout, and os.Stderr, preserving the same child-stdio behavior across supported Unix targets.

The Ubuntu UT and coverage failures on the preceding head stopped in Set up Go before test execution. The connector failure was source-related and is fixed here. git diff --check and the refreshed exact-head schema-v6 semantic preflight pass; fresh CI is required for the updated head.

Please re-review this exact Ready head.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

@XuPeng-SH Follow-up for exact head dc8a2be98bae15a72cf29bdbdaf33ef06a0f1aec (base 99ed717b769e261b842c2f17345bd65865fc1470).

This update addresses the two exact-head local reproductions behind the previous red UT/Coverage checks:

  • Do not start saveProfilesLoop when -profile-interval=0; this removes the shutdown test/runtime cleanup race on the mutable profile flag.
  • Run the reaped-child boundary regression through the production default process Signal/Wait hooks and accept clean completion after ownership has already been cleared, while retaining the assertion that only SIGTERM was sent and no SIGKILL followed reap.

Validation on the exact candidate:

  • mo-cgo-test -race -count=100 -run TestDynamicShutdownDoesNotEscalateAfterWaitReapsChild: PASS
  • mo-cgo-test -race -count=100 -run TestConfiguredProxyStartupFailureWakesShutdown: PASS
  • Full cmd/mo-service package under -race: PASS
  • Semantic preflight: PASS, final diff hash 32dac2eb7987726af00ab9379ea25a630db84eb0cf0e42c492f36e8d59b12fd2
  • gofmt and git diff --check: PASS

The prior required run 34039063834 is superseded by this head; fresh exact-head CI is pending. Please re-review this exact head. QA remains required.

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

Deep re-review of dc8a2be. The previous async configured-Proxy startup notification and stale raw-PID signaling findings are addressed. Role ordering and Python-provider lifetime are also improved. Two failure-closure issues remain, both reproduced with review-only tests against this head (see inline comments).

Verification: inspected all changed production files and tests, traced normal/startup/fatal shutdown separately, ran the existing focused supervisor/dynamic-shutdown tests plus two new counterexamples through the controlled macOS CGo wrapper. Existing selected tests did not fail; both counterexamples failed as described. git diff --check passed. No production edits, restart workload, or Linux-specific execution is claimed.

Please fix the distinction between successful reaping and successful CN shutdown, and make child ownership cleanup common to every terminal error path, without cancelling in-process dependencies out of order. Add production-boundary regressions for nonzero/signaled exit and normal-signal/HAKeeper shutdown with Proxy close failure.

Comment thread cmd/mo-service/dynamic.go Resolved
Comment thread cmd/mo-service/main.go Resolved

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

Deep re-review of exact head dc8a2be98bae15a72cf29bdbdaf33ef06a0f1aec against base 99ed717b769e261b842c2f17345bd65865fc1470: REQUEST_CHANGES.

I read the full review/comment/thread history, checked the complete diff, and separately audited the increment since my prior review at f88c875cdf1202d1399760c8da8f6fcd6e09731e. The earlier dynamic-CN producer/snapshot race is closed, as are the later timeout escalation, configured-Proxy error propagation, Python ordering, async Proxy failure notification, and stale raw-PID signaling findings. Two exact-head shutdown invariants remain open (inline).

I reproduced both with review-only tests on Linux at this exact head: (1) a real /bin/sh -c 'exit 23' child was reaped but stopAllDynamicCNServicesGracefully returned nil; (2) the HAKeeper/normal path returned a configured-Proxy close error with cleanupCalls=0. The temporary tests were removed. make thirdparties; normal tests for pkg/common/chaos, pkg/cnservice, and cmd/mo-service; focused race tests for chaos/supervisor/dynamic/proxy paths; and git diff --check all pass. Exact-head GitHub CI is green.

Comment thread cmd/mo-service/dynamic.go Resolved
Comment thread cmd/mo-service/main.go Resolved
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed and pushed at exact head 89fc25fb61434f56aa8f5154219c439a135b2ca3.

  • osDynamicProcess.wait() now preserves ProcessState: clean exit succeeds, nonzero/signal exit returns a shutdown error, and every successfully reaped matching PID/handle is cleared.
  • Terminal shutdown errors now run one bounded, idempotent dynamic-child cleanup before fail-stop, including normal SIGTERM/SIGINT and HAKeeper paths. Failed Proxy/CN barriers still do not advance later dependencies.
  • Added production-boundary coverage for real exit 0, exit 23, signal termination, timeout-to-SIGKILL, normal signal shutdown, and HAKeeper shutdown with child liveness/reap and CN-barrier assertions.

Validation on this exact content:

  • cmd/mo-service normal package tests: PASS.
  • cmd/mo-service full package race: PASS.
  • Affected lifecycle regressions: race -count=100, PASS with no race report.
  • go list, CGo-aware go build, go vet, git diff --check, self-review, and semantic preflight: PASS.
  • BVT: N/A. SQL BVT cannot deterministically signal/reap standalone OS children or inspect supervisor dependency barriers; the production-boundary Go tests cover those contracts.
  • QA remains required for deployed standalone/restart lifecycle acceptance.

The required checks for the superseded head were green before this push; fresh checks for this exact head are left to the normal PR workflow and were not rerun manually.

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

Deep re-review of 89fc25f against base 99ed717: REQUEST_CHANGES for one P2 test-oracle race.

The previous two production blockers are resolved: Wait now distinguishes successful reaping from clean child exit, releasing matching ownership even on nonzero/signal termination; every shutdown error now reaches common once-only dynamic-child cleanup. I reviewed the full production change map, test changes and earlier findings, including phase ordering, Python lifetime, async Proxy failure notification, partial startup, process identity, escalation, and repeated shutdown. I found no additional concrete production blocker in that pass.

P2 — The post-reap test can reject a valid cancellation outcome

In cmd/mo-service/dynamic_shutdown_race_repro_test.go, TestDynamicShutdownDoesNotEscalateAfterWaitReapsChild observes the ownership slot becoming zero, calls cancel(), then requires NoError from shutdown. Slot clearing does not establish that shutdown has consumed the wait result.

Concrete legal schedule:

  1. The wait goroutine clears the slot under dynamicCNMu, unlocks, and is preempted before sending on the unbuffered results channel (dynamic.go, startWait).
  2. The test sees the cleared slot and cancels the context.
  3. The shutdown select takes ctx.Done, records context.Canceled, sees no remaining owned child, and therefore correctly sends no SIGKILL.
  4. The waiter resumes and sends its successful result; shutdown drains it and returns context.Canceled.
  5. The test's require.NoError fails although the no-post-reap-SIGKILL invariant holds. The same outcome is permitted when both select cases are ready.

Please allow nil or context.Canceled in this cancellation-boundary test while retaining the exact no-SIGKILL/ownership assertions, or add explicit barriers that establish the particular ordering the oracle requires. Slot visibility alone cannot prove result consumption. This is a flaky assertion, not missing test evidence or a newly identified production shutdown defect.

Validation: current-head CI run 34081345033 has passing UT, SCA, coverage and proxy/multi-CN BVT. I ran a minimal standard-library scheduling model using the same clear-slot/unbuffered-result/select protocol, with barriers selecting the interleaving above: slotCleared=true shutdownError=context canceled SIGKILLCount=0 NoErrorOraclePass=false. This was a scheduling proof, not an execution of the full MatrixOne test; no local native/full-suite PASS is claimed. No repository source was modified. Deployed restart/upgrade acceptance remains as documented in the PR.

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

Re-reviewed exact head 89fc25fb61434f56aa8f5154219c439a135b2ca3, including every prior review/thread, the complete PR diff, and the increment since my previous reviewed head dc8a2be98bae15a72cf29bdbdaf33ef06a0f1aec. The two previous production blockers are closed: child exit status is now preserved, and normal signal/HAKeeper shutdown failures share the bounded dynamic-CN cleanup path. One deterministic test-oracle race remains, described inline, so I am requesting changes. Validation on the exact head: affected package tests passed; focused race tests passed 100 runs; the current test passed 10,000 normal and 1,000 race runs; vet and diff checks passed. A barrier-controlled counterexample reproduced the legal failing schedule 100/100 times and was removed afterward.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the shutdown-race follow-up and pushed exact head 505377b0a5d2340389f7d4f0f9395671450a42d2 (base 99ed717b769e261b842c2f17345bd65865fc1470).

  • stopDynamicCNByIndex now owns the child through Wait, tolerates an already-completed process, and clears only the matching PID/process generation after a successful reap.
  • Graceful shutdown preserves terminal child outcomes while treating an already-done signal as a wait-owned boundary.
  • The cancellation-sensitive regression now accepts nil or context.Canceled after the waiter has already cleared ownership, while still asserting no unnecessary SIGKILL and correct slot/reap behavior.

Validation at this exact head: controlled CGo focused dynamic tests PASS; TestDynamic under -race -count=100 PASS; full cmd/mo-service CGo race package PASS; git diff --check PASS; semantic preflight PASS (diff_hash=76f02dbebc7409514831d68405544de1281b187134d77587f2e8776af03bb09d). Fresh required CI is pending on the new head. Please re-review the exact head; QA for #27945 remains separate and still has its tester-failed state.

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

Deep re-review of exact head 505377b0a5d2340389f7d4f0f9395671450a42d2: approve. The prior requested change is closed.

The reaped-child cancellation test now accepts either nil or context.Canceled while retaining the no-SIGKILL assertion. That matches the actual valid schedules: slot ownership can be cleared before the wait-result send is received, and cancellation can win the select in that interval. The old flaky NoError oracle is no longer imposed; unrelated errors are still rejected.

The additional force-stop repair is sound: SIGKILL no longer clears the only child slot before Wait consumes its status. The slot remains owned through reap, restart is excluded under the existing dynamic mutex, and graceful shutdown cannot concurrently claim that child because it sets/checks the same stopping state under the mutex. A successful reap of an intentional SIGKILL is treated as success for chaos stop; graceful shutdown still reports abnormal exit status. ErrProcessDone is tolerated for signaling while Wait remains the ownership oracle. The real-child test checks that a second wait cannot reap it again.

I rechecked the unchanged graceful escalation path: generation/object plus PID identity protects slot clearing and post-cancellation escalation; already-reaped slots are not killed; wait results are collected before returning. Failed reap retains ownership and propagates an error rather than pretending the child disappeared. No new goroutine, hot-query-path work or data-format contract is introduced by this increment. As before, reap completion relies on the OS completing process termination; this is not a claim of a hard deadline against an uninterruptible kernel wait.

Evidence: exact delta from previously reviewed 89fc25f (two files), current child ownership/start/stop/cleanup source, new test oracles, and existing green current-head CI. The broader supervisor/dependency-order review from the previous head remains applicable because that code is unchanged. No new local native execution or benchmark is claimed. No concrete remaining blocker found.

@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 08:09 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 08:42 UTC · at 64fb592fbc1ca065a67d8d417cc14f1265a3b128

This pull request spent 32 minutes 55 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28015 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

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

Deep re-review completed on exact head 505377b.

I read the complete review/comment/thread history, rechecked the full 13-file change, and audited the increment since my previous reviewed head 89fc25f. The prior test-oracle blocker is closed: the shutdown race test now accepts both valid completion outcomes (nil and context.Canceled) while preserving the assertions that no SIGKILL is sent and the child slot is cleared.

The new force-stop/reap path is internally consistent: dynamicCNMu prevents restart or graceful-shutdown overlap; ownership remains in the slot through SIGKILL and Wait; the slot is cleared only for the matching child generation after a confirmed reap; and expected signal-exit status is ignored only on the explicit force-stop path. Treating os.ErrProcessDone from Signal as non-fatal is also sound because Wait remains the reaping/ownership oracle.

Validation on this exact head:

  • go test -count=1 ./cmd/mo-service ./pkg/common/chaos ./pkg/cnservice
  • focused dynamic shutdown/reap race tests with -race -count=100
  • full ./cmd/mo-service with -race -count=1
  • git diff --check

No remaining blocking issue found.

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/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants