Skip to content

fix: quiesce and drain TN RPC handlers before storage close #28012

Closed

Description

@VioletQwQ-0

Is there an existing issue for the same bug?

Branch Name

main

Commit ID

c46d897e9645b80178568ef0783dd8e99e527222

Other Environment Information

Actual Behavior

During standalone graceful shutdown, accepted TN transaction RPC handlers can remain active while TN replicas or storage are being cancelled and while the process-level shutdown advances toward LogService shutdown.

In the captured failure, exactly two TN RPC workers remained inside the transaction commit path:

TN transaction RPC worker
→ TAE Txn.commit1PC()
→ txnStore.WaitWalAndTail()
→ WAL entry.WaitDone()
→ LogService append

The TN RPC server does not expose a lifecycle boundary that first rejects new producers and then drains already accepted handlers. Queued, local-dispatch, forwarded, and active requests therefore do not share one sealed accounting model, and shutdown cannot prove that every accepted handler reached a terminal state before replica/storage dependencies are closed.

This can make a dependency-ordered standalone shutdown stall or destroy resources still needed by accepted commits. It also makes repeated or concurrent close behavior difficult to reason about.

Expected Behavior

TN transaction RPC shutdown should follow a private, bounded lifecycle:

Quiesce
→ Drain accepted handlers
→ Close replicas and storage

After the quiesce linearization point, network and local-dispatch producers must be rejected and the accepted-handler count must not increase. Queued requests must be cancelled and released exactly once. Active handlers must retain replica, storage, and WAL dependencies until they reach a terminal state.

If drain reaches its deadline, shutdown must return a deterministic error without destroying dependencies that active handlers still require. A commit that has entered the durability stage must not be reported as rolled back merely because the client disconnected or shutdown began.

Steps to Reproduce

  1. Start a standalone MatrixOne process containing CN, TN, LogService, and HAKeeper.
  2. Establish at least two transaction RPC requests and pause or delay them after the server has accepted them but before their WAL durability terminal is published.
  3. Send SIGTERM to begin graceful standalone shutdown.
  4. Observe TN shutdown while the accepted RPC handlers are still active.
  5. Without an explicit quiesce/drain boundary, new/local producers can race with shutdown and replica/storage cancellation can overlap the accepted handlers.
  6. Confirm the terminal wait chain with the TN RPC worker and WAL waiter goroutine stacks.

The deterministic regression coverage for the fix should exercise queued, forwarded-wait, local-dispatch, handler-active, and durability-stage requests, including repeated close and drain timeout.

Additional information

Activity

  1. added
    kind/bug
    severity/s0
    on Sep 3, 2026
  2. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    转 QA:开发侧证据交接(非正式 QA PASS)

    验证绑定合入版本 92a6bceba1ee156b87dc340479aa1cd44fe56a3d,A+C 对照为 585a38efd152fadf216c8675b7b997a35ca8deb1。

    • D1:真实 wrappedClient.Append 前的 pending entry,3/3 通过;
    • D2:真实 append 成功、waiter 通知前,PSN 存在且 waiter 未提前完成,3/3 通过;
    • U2:durability 阶段客户端断开后恢复,3/3 原子恢复,无 partial/duplicate/checksum mismatch;
    • 事件证明 CN withdrawal → HAKeeper、TN drain/storage → TN、TN → LogService 的关闭依赖顺序正确。

    D1/D2/U2 使用测试专用 overlay,仅标记 INSTRUMENTED_RUNTIME_VERIFIED;原版 binary 用于恢复检查。两次早期 U2 harness 失败已保留并排除,不计入通过次数。

    证据包:/home/sunyuze/lifecycle-closeout-v2-e295-20260908-01/qa-closeout-20260909/real-wal-boundary-20260909-final/;manifest SHA256:b874e69507bebf2c4da96317bba4d8542236c43d4cf786471210585130052ee8。

    请 QA 绑定 exact 版本和环境复核 Quiesce/Drain、依赖关闭和事务恢复;本评论表示开发证据已提交,不表示正式 QA PASS。issue 保持 OPEN。

  3. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    Collaborator

    回归补充

    已新增独立回归 PR #28730,不与 SQL/MOTR 用例混放。

    • 测试:TestIssue28012And28013AcceptedCommitDuringStandaloneShutdown;真实 embedded 单 CN/TN/LogService。
    • 注入点:事务已完成 WaitWalAndTail()、尚未执行 on1PCApply 的 FJ_CommitWait。
    • 场景:保持已受理的三行事务,触发 standalone shutdown;关闭进入后不得在该事务拿到终态前返回。释放 WAL 后边界后,验证关闭有界完成;用相同持久化数据重启,三行写入只能完整可见或完整缺席;最后执行新事务证明服务恢复可用。
    • 本地验证:PR head ff8516842d95138c2c73a7e1a520fce088708459,目标用例连续 3/3 通过;go test ./pkg/tests/issues/isolated -count=1 通过。

    该 PR 仅补充自动化 QA gate,当前等待 review、CI 和合入 main;在合入后的 exact-head 复验完成前,此 issue 保持 Open。

  4. iamlinjunhong commented on Sep 24, 2026

    @iamlinjunhong
    Contributor

    2026-09-24 CI evidence for PR #29152

    The source PR is still open at exact head 18341dda0710d94461fee48db2750b9a218ba693. Run 35870543875, attempt 1, has three failed checks:

    • UT Coverage on Ubuntu/x86, job 107213330503 failed in TestIssue28012And28013AcceptedCommitDuringStandaloneShutdown. The test did not observe the TN drainWaiters fault point within 30 seconds (pkg/tests/issues/isolated/issue_28012_28013_shutdown_test.go:146); cleanup then reported issue 28012/28013 goroutines did not exit within 30s and bad connection. The same log records a timeout subscribing to mo_debug.trace_features and refused task-service connections during shutdown.
    • Coverage, job 107236344476 failed its prerequisite check because the UT producer did not publish a complete coverage profile. No coverage verdict was calculated.
    • CI Required, job 107236429129 reports matrixone-ut-coverage: failure, downstream of the UT result.

    An independent Linux/x86 CI failure of the same exact test occurred on unrelated PR #28730: run 35332206856, attempt 1, job 105558897895. It ended with context deadline exceeded after embedded-cluster admission waited about 2m59s; that run reports the test elapsed 222.69s. The low-level timeout point differs, but both are timeouts in this shutdown regression case. The maintainer analysis and the test contract linked from this issue cover TN handler drain while an accepted commit is blocked.

    The current exact head's separate Linux/x86 UT job 107213274028 succeeded and reports this same test passing in 32.95s. The failing case and TN RPC/WAL drain implementation were not changed by PR #29152. The only nearby shutdown edit adds optional UDF runtime cleanup in CN; this test leaves Python disabled, so CN receives an empty runtime registry whose Close has no runtime to close. The failed job runs the external matrixorigin/CI coverage workflow, not the optools/run_ut.sh path also edited by the PR.

    The evidence matches the existing open shutdown lifecycle/test-contract issue and its independently observed Linux/x86 timeout class. The other two current failures are downstream of the UT producer failure. This run is recorded here for the single authorized failed-jobs rerun.

  5. Ariznawlll commented on Sep 24, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d7d940e93bd037e9aacdc0f1256b91e32df84642
    • 环境:本地 Go integration test

    原问题验证

    执行精确回归 TestIssue28012And28013AcceptedCommitDuringStandaloneShutdown,连续运行 3 次,覆盖 standalone TN 在已接受 commit 与 storage shutdown 并发时的 drain/quiesce 行为。测试 3/3 通过,总耗时 55.218s,未出现 RPC handler 在 storage close 后继续访问导致的失败。

    正常场景覆盖

    • commit 已被 TN 接受后进入关闭流程。
    • RPC handler 完成 drain 后再关闭 storage。
    • restart 后验证已接受事务的持久化结果。

    异常与边界覆盖

    • shutdown 与 accepted commit 的并发窗口。
    • handler 尚未退出时的 storage close 顺序约束。
    • 连续 3 轮运行验证无偶发超时或丢提交。

    白盒验证

    该问题依赖内部 fault injection、TN 生命周期和 restart 检查,精确覆盖位于 MatrixOne Go integration test;SQL 黑盒 MOTR 无法可靠制造“commit 已接受但 handler 尚未 drain”的内部时序,因此不重复添加一个弱化用例。

    回归测试

    • MatrixOne:TestIssue28012And28013AcceptedCommitDuringStandaloneShutdown
    • 执行:-count=3
    • 结果:PASS,55.218s。

    测试证据

    • 三次 accepted-commit / shutdown / restart 流程全部通过。
    • 精确测试覆盖 internal handler drain 和 storage close 的先后关系。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions