Skip to content

test: add regression guard for pipeline terminal loss under lock wait backpressure - #30369

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-24971-regression-main
Oct 17, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-24971-regression-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 16, 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:

issue #24971

What this PR does / why we need it:

Adds an end-to-end regression UT that locks in the recovery behavior fixed for the pipeline terminal protocol (#25273 and its follow-ups).

Background: on the pre-#25273 protocol (e.g. v4.1.2), a DML pipeline whose consumer side was blocked on a row lock could lose its terminal (End) notification during cleanup backpressure. Once the blocking lock was released, the query stayed stuck in PipelineSignalReceiver while still holding its acquired row locks, so later writers on the same keys queued behind it until the session was killed. This amplified lock chains and memory buildup in production.

The test lives in pkg/tests/issues/isolated and starts its cluster via embed.StartTestCluster, so it goes through cluster admission instead of bypassing it. On a single embedded CN it builds the vulnerable shape: a REPLACE INTO ... SELECT whose plan has a merge/connector edge (Sink Scan) above Lock. Session A holds a row lock; session B runs the REPLACE; after a backpressure window in which B is asserted to still be in the lock wait, A rolls back. Assertions:

  • B finishes successfully after the blocking lock is released (bounded wait; dumps relevant goroutine stacks on timeout instead of hanging CI),
  • all rows are written (data completeness),
  • all locks are released,
  • a third statement on the same key is not blocked,
  • the plan shape (Lock + Sink Scan) is asserted so an optimizer change cannot silently invalidate the case.

Layering note: the channel-full terminal contract itself (End recorded as durable edge state, receiver synthesizes an End that did not fit, spool abort on undeliverable terminals) is guarded by the component-level tests in pkg/sql/colexec/connector/types_test.go, notably TestConnectorResetRecordsEndWhenDataChannelIsFull, TestConnectorResetDurableEndWakesReceiverAfterBufferedData, and TestConnectorResetAbortsSpoolWhenTerminalSignalCannotBeDelivered. From SQL there is no observable terminal-send barrier: on the current protocol the producer is parked in the data phase (WaitPipelineSignalCapacity) while the consumer waits on the lock, so no terminal send occurs during the hold window by design. This test therefore guards the end-to-end recovery outcome, and intentionally does not assert the absence of cleanup warnings (the abort fallback is also a valid outcome).

Tests you have done (required):

  • add UT
  • go test -v -count=1 -run ^TestIssue24971LockWaitBackpressureRecovery ./pkg/tests/issues/isolated — PASS (~13s)
  • go vet ./pkg/tests/issues/isolated — pass
  • gofmt — pass

… backpressure

Regression UT for issue matrixorigin#24971: on a single embedded CN, a REPLACE INTO
... SELECT plan with a merge/connector edge above Lock must recover
correctly when its consumer side is blocked on a row lock held by
another session. After the blocking lock is released, the query must
finish successfully with all rows written and all locks released, and
a later statement on the same key must not be blocked.

Shortens the terminal-signal send timeout in-test (same pattern as
compile/remoterun_test.go and colexec/connector/types_test.go) so the
whole case runs in ~17s.
…verride

- Move the test to pkg/tests/issues/isolated and start the cluster via
  embed.StartTestCluster so it goes through cluster admission instead of
  bypassing it with a bare NewCluster.
- Drop the PipelineSignalSendTimeout override: production code no longer
  reads it; the hold window is now a backpressure scenario parameter that
  also asserts the lock wait stays live for the whole window.
- Document the layering: the channel-full terminal contract is guarded by
  the component-level tests in pkg/sql/colexec/connector; this test guards
  the end-to-end recovery outcome.
@ck89119

ck89119 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

As a follow-up to the review point on terminal-phase coverage: below is the failure contrast of the same SQL-level scenario on the unfixed version, run locally before this PR was written. It shows the guarded failure mode is real at the SQL level on the old protocol, and that the new UT fails exactly there if the behavior regresses (B never finishes after the blocking lock is released).

Setup: same shape as the UT in this PR — single embedded CN, synthetic file/file_working tables, 16,384 rows, the same two-row recursive-CTE REPLACE INTO ... SELECT (plan has Sink Scan above Lock), session A holding SELECT ... FOR UPDATE, session B running the REPLACE. Base: ce99d329cf584e162fb945f62fe8d046706126f7 (v4.1.2, the pre-#25273 protocol).

Observed on v4.1.2 (times relative to B starting):

  1. B enters a real lock wait (lock-service waiter confirmed for B's txn).
  2. ~30s: connector cleanup timed out enqueueing terminal spool message: timeout=30s query_done=true err=<nil>
  3. ~60s: connector cleanup timed out sending terminal direct signal: timeout=30s channel_len=1 channel_cap=1 pipeline_failed=false err=<nil> (connector_cleanup_send_terminal_signal counter 0→1)
  4. A rolls back. B acquires the row locks (count=16384 on the target table) but the query never returns. A third session UPDATE ... WHERE id=1 queues behind B's locks.
  5. Goroutine stack of B's pipeline at that point — blocked in the receiver, not in the lock wait:
(*PipelineSignalReceiver).listenToSingleEntry   pkg/vm/process/process_spoolr.go
(*PipelineSignalReceiver).listenToAll
(*PipelineSignalReceiver).GetNextBatch
(*Merge).Call                                    pkg/sql/colexec/merge/merge.go
  1. kill query on B does not take effect until the merge cleanup timeout fires ~30s later (merge cleanup timed out waiting for pipeline end signals: timeout=30s alive=1), then the txn rolls back, all 16,384 locks are released, and the queued third statement completes.
  2. Control sub-case (releasing A before the terminal timeouts) completes normally.

On current main (and on v4.2.0, the first release containing #25273), the identical scenario produces no cleanup warnings at all: the producer is parked in the data phase (WaitPipelineSignalCapacity) while B waits on the lock, and after A rolls back B finishes successfully with all 16,384 rows written, locks cleared, and the third statement unblocked. That outcome is what this PR's UT pins down.

So the layering is: the channel-full terminal contract (durable End, receiver-side synthesis, spool abort) is guarded by the component-level tests in pkg/sql/colexec/connector/types_test.go; this UT guards the end-to-end recovery outcome, and on a regression back to the old behavior it fails via "query B did not finish after the blocking lock was released" plus the dumped receiver stacks.

@ck89119
ck89119 marked this pull request as ready for review October 16, 2026 07:49
@ck89119
ck89119 requested a review from XuPeng-SH as a code owner October 16, 2026 07:49
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 488168a3adfac20ae6dc246f30dbc7247646f99f

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 488168a3adfac20ae6dc246f30dbc7247646f99f

Assessment: request_changes

Reviewed the complete test-only delta and its cluster, lock, pipeline, and cleanup owners. Reusing existing owners is reasonable, but the committed scenario does not match the documented terminal-loss trigger. No production runtime paths change.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/tests/issues/isolated/issue_24971_test.go:120: Validation requirement: the delayed scenario releases A after 8 seconds, whereas the supplied unfixed-version reproduction requires two successive 30-second terminal-cleanup timeouts before releasing A.
    Impact: The supplied negative control does not establish that this regression guard detects the original failure. It instead documents that early release succeeds on the unfixed protocol. Use controlled timeout or phase injection and demonstrate fail-before/pass-after with the exact committed scenario.
    Evidence: Author comment 6210225557 reports terminal enqueue timeout at approximately 30s, direct-signal timeout at approximately 60s, and successful completion when A is released before those timeouts. The test uses hold windows of 0s and 8s without shortening cleanup timeouts; process_spoolr.go retains PipelineSignalSendTimeout = 30*time.Second. The comment at lines 161–162 claiming the hold exceeds terminal-send timeouts is therefore unsupported.

Validation:

  • Frozen head and clean source verified; all 368 added lines and surrounding owners reviewed. git diff --check and gofmt passed.

  • Artifacts retained under /home/xupeng/.local/state/mo-bot/jobs/94a9669606dfb4d587c4494e/attempt-1. Reconciled preflight.log with checks/1792146538010608401-4.json and review-static.log with checks/1792146658296743595-4.json; both exited 0 with the assigned source fingerprint.

  • Native recovery verified the retained provider's provenance and matching native source trees. Current-revision preparation through make cgo timed out during Go 1.27.1 download after repeated TLS failures: native-build.log and checks/1792146853030574953-4.json, exit 124.

  • Frozen evidence records successful Ubuntu UT and Linux SCA checks. local_validation is empty; no retained author execution receipts establish the exact negative-control scenario.

Limitations:

  • No local Go tests executed because toolchain bootstrap failed. This is an environment limitation, not a product-test failure or the reason for requesting changes.

  • The historical failure was assessed from the supplied reproduction narrative, not independently rerun. Exact-scenario regression discrimination remains required.

  • The added cluster and 8-second hold increase test cost; the author's approximately 13-second runtime was not independently measured.

The delayed sub-case released the blocking lock after 8s, which on the
unfixed protocol is just the already-green early control: terminal End
loss requires two successive cleanup timeouts (spool enqueue ~30s,
then direct signal ~30s). Hold the backpressure for
2*process.PipelineSignalSendTimeout plus margin, so a regression back
to losing the terminal signal is caught by query B never finishing.

Fail-before/pass-after verified with the exact committed scenario:
- PASS on main (75s): B finishes, all rows written, locks cleared,
  later statement unblocked.
- FAIL on v4.1.2 (pre-matrixorigin#25273): after the two 30s cleanup timeouts,
  B holds the row locks and never returns until killed.
Also relax the MySQL readTimeout so a client-side connection timeout
cannot mask the server-side hang during negative checks.
@ck89119

ck89119 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Addressed the P2 in c777231c51: the delayed hold window is now 2*process.PipelineSignalSendTimeout + 10s (70s), which strictly exceeds the unfixed protocol's worst case for losing the terminal End signal (spool-enqueue timeout ~30s, then direct-signal timeout ~30s). The 8s window was indeed only the already-green early control.

Fail-before / pass-after with the exact committed scenario (same test, same shape, only the cluster bootstrap differs because v4.1.2 has no embed.StartTestCluster; the later StartTestCluster is exactly NewCluster(WithTesting(), ...) + Start):

Run Base Result
Immediate control both PASS (releases A before any terminal timeout; B completes normally)
Delated hold (70s) main @ 88a31fd01a PASS (75s): B finishes after A rolls back, 16,384 rows written, locks cleared, third statement unblocked
Delayed hold (70s) v4.1.2 ce99d329cf584e162fb945f62fe8d046706126f7 (pre-#25273) FAIL (176s), exact assertion: query B did not finish after the blocking lock was released; possible terminal-signal loss regression

On the v4.1.2 run the two 30s cleanup warnings appear inside the hold window (connector cleanup timed out enqueueing terminal spool message at ~30s, connector cleanup timed out sending terminal direct signal at ~60s), and B never returns after A rolls back — matching the supplied reproduction narrative.

One fix applied during negative-checking: the original run failed early with a client-side invalid connection because the MySQL readTimeout=120s was shorter than the hold+wait window and masked the server-side hang. The test now uses readTimeout=300s so the failure reason is the guarded assertion itself rather than a driver timeout.

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

Request changes on 88a31fd01aee3de1bc7add1a6134b65c21822e3d (base ac9dbfeeec2caba32f06c998cb0132d416d72000). Reviewed all 376 added lines and the existing cluster-admission, connector/spool, receiver, lock-observation, and test teardown owners. Production code and docs have no delta.

The earlier 8-second negative-control finding has been substantively addressed: the new comment supplies an exact-scenario old-protocol failure/current-head pass, and the committed hold now exceeds both 30-second cleanup timeouts. I am not repeating that old finding. The remaining blocker is the resulting ordinary-UT cost/control design.

[P2] Replace the production-duration hold with a controlled regression trigger.

delayedWindow := 2*process.PipelineSignalSendTimeout + 10*time.Second makes every successful normal UT spend at least 70 seconds holding an admitted embedded cluster, with repeated lock-table scans. Independent current-head measurement: immediate control 0.20s, delayed control 70.15s, root 74.81s (package 76.635s, excluding compilation). This is a deterministic increase to each default UT/coverage/race invocation, not build time or admission contention. A longer hold only observes that B remains a lock waiter; it still does not establish a producer-side terminal/backpressure phase.

The repository already owns configurable cleanup timeouts (pkg/vm/process/process_spoolr.go) and deterministic full-channel End/receiver/spool tests (pkg/sql/colexec/connector/types_test.go, including tests that scope PipelineSignalSendTimeout to 10ms). Please use a safely scoped timeout/phase control for this isolated SQL scenario, with restoration after cluster shutdown, or retain a small SQL recovery case and put real-duration qualification in the appropriate slow/stability suite. Preserve the exact fail-before/pass-after distinction after changing the control; merely reverting to the old 8-second sleep would not fix it. Record the minimum batch/cardinality requirement and measured fixture cost. The 70-second production timeout is not itself the SQL correctness contract.

Validation: verified native build passed; exact committed test passed normally and under -race -count=1 with both subcases selected. Race package elapsed 107.955s; no race reported. Since this one race run already exceeds the 30s adaptive repetition budget, N=1. CI Ubuntu UT/Linux SCA are also green. No old-binary reproduction was independently rerun; the author-supplied negative control remains attributed as such.

Other closure checks: query-result publication is synchronized by closing done; fixture admission and cluster Close remain with embed; SQL/lock/follower success oracles are useful; no production performance change. Cleanup kill-query/kill-connection paths and connection/defer ordering were traced. These successes do not remove the avoidable default-suite waiting cost.

Scope process.PipelineSignalSendTimeout to 2s before the cluster starts
and restore it after cluster shutdown via cleanup ordering, following
the connector/edge tests that scope the same variable. The override is
inert on the current protocol (production no longer reads it), but a
regression back to the old read-it-and-drop-it cleanup path honors the
scoped value, so the End loss lands inside the 6s hold window and the
guard fails fast instead of paying 2x30s per successful run.

Fail-before/pass-after re-verified with the exact committed control:
- main: PASS 12.24s normal, 13.33s under -race (was 75s/108s).
- v4.1.2 (pre-matrixorigin#25273): FAIL with the guarded assertion; both cleanup
  warnings show timeout=2s inside the hold window.
Also record the observed working cardinality (16,384 rows) and the
measured fixture cost in the test comments.
@ck89119

ck89119 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Addressed the P2 in 4eccd3756e: the production-duration hold is replaced by a controlled timeout scope.

  • process.PipelineSignalSendTimeout is set to 2s before the cluster starts and restored after cluster shutdown (the restore cleanup is registered before the cluster's own cleanup; cleanups run LIFO, so shutdown happens first). This follows the existing connector/edge tests that scope the same variable.
  • The delayed hold window is now 2*2s + 2s = 6s. The override is inert on the current protocol — production no longer reads the variable — so a green run pays 6s, not 70s. A regression that reinstates the old read-it-and-drop-it cleanup path honors the scoped value, so the End loss lands inside the hold window and the guard fails via B never finishing.
  • Fail-before/pass-after was re-verified with the exact committed control:
    • main: PASS, 12.24s normal / 13.33s -race (previously 74.8s / 107.9s).
    • v4.1.2 ce99d329cf584e162fb945f62fe8d046706126f7: FAIL (exit 1) with the guarded assertion query B did not finish after the blocking lock was released; both cleanup warnings in the log show timeout=2s and both fire inside the 6s hold window (connector cleanup timed out enqueueing terminal spool message at ~2s, ... sending terminal direct signal at ~4s). The immediate-release control passes on both bases.
  • Minimum batch/cardinality and fixture cost are now recorded in the test comments: 16,384 rows is the observed working cardinality that overflows the plan's sink/merge buffering while B waits on the lock; measured cost ~12s normal / ~13s -race, dominated by the 6s hold window.

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

Approve 4eccd37. No remaining blocking findings after reviewing the complete 398-line test, its SQL/lock/pipeline owners, and all prior review comments.

The earlier findings are substantively addressed: the delayed case now uses a 2s cleanup-timeout scope and a 6s hold, with author-reported exact-control fail-before/pass-after evidence. I checked that the historical connector really reads the scoped variable for both cleanup sends. The override is installed before cluster startup and restored after cluster Close via LIFO cleanup; this package has no parallel tests, and current production code does not read that variable. The 70s ordinary-UT cost is gone.

The test reuses embed admission, real SQL connections and lock-service observation. Its SQL recovery/completeness/lock-release/follower oracles complement the existing deterministic full-channel terminal tests without adding a production state machine. Increment: production 0, tests +398, separate documentation 0.

Independent local validation on the exact head, darwin/arm64, Go 1.27.1, GOMAXPROCS=4, through mo-cgo-test:

  • Named normal regression PASS: root 11.77s; immediate 0.11s, delayed 6.13s.
  • Named race measurement PASS: root 11.71s. Adaptive N=floor(30/11.71)=2; same-process -race -count=2 PASS, roots 11.84s and 11.67s. Both subcases ran each time; no race report.
  • Cluster admission and port leases released after every run; source tree clean; diff-check and gofmt passed. Current-head Ubuntu UT and Linux SCA checks are successful.

The historical failing binary was not independently rerun in this review; that negative control is attributed to the author's linked results. Coverage here is the single-CN SQL recovery scenario, with protocol-specific failure coverage owned by the existing component tests. No production performance path changes.

@mergify mergify Bot added the queued label Oct 17, 2026
@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-17 14:54 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-17 15:48 UTC · at ff2acc1ace1a4b8a37dde011a9aa529ff2286c30 · squash

This pull request spent 54 minutes 23 seconds in the queue, including 53 minutes 53 seconds running CI.

Required conditions to merge

XuPeng-SH commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

独立合并后功能验证完成,未用合并/CI 状态代替执行。

main d304047724bea6104c5c2be496107928034b0778(包含本 PR 的 ff2acc1ace1a4b8a37dde011a9aa529ff2286c30),Go1.27.1/Linux amd64 CPU/CGo:

  • 实际构建并执行 TestIssue24971LockWaitBackpressureRecovery 普通与 race 均通过,各 3 个测试/子测试事件,0 失败/跳过。测试本体分别 10.75s、16.47s(不含首次编译)。
  • 走真实 MySQL 会话,EXPLAIN 验证 Lock + Sink Scan;立即释放与延迟 6s 的两个对照都验证:阻塞期间真实 lock waiter 存在,释放后 REPLACE SELECT 成功,16,384 行完整写入,锁数归零,后续同键 UPDATE 不阻塞。
  • Connector 完整归属包普通/race 各 13 个通过,包含 channel-full durable End、buffer drain 后唤醒 receiver、undeliverable terminal 的 spool abort、error/cancel/cleanup 控制。
  • 按实测 race 时长和30s预算,精确 SQL 测试另跑 -race -count=1(floor(30/16.47)=1),通过;同一进程没有扩大选择或修改断言。

4.2-dev ac27db31696c0394ab1b2787b7b0a8f4933f088f,Go1.26.4:

  • 同一公开 SQL/计划/锁/行数/后续 writer 断言经 Go overlay 运行,普通/race 均通过,各3事件。
  • 初始直接复制 main 测试时,SkipCheckUser=true 的合成身份在4.2被鉴权校验拒绝,CREATE DATABASE 阶段即失败,未进入管线场景。保留两份失败日志;最终仅在诊断夹具中改成 SkipCheckUser=false 使用正常 dump:111 认证,SQL 和行为断言完全不改,重跑才计为通过。生产源码未改,也不把初始鉴权失败当作管线回归。
  • 这是4.2实际执行证据;本 PR 本身只合入 main,没有声称它已经 backport。

命令:仓库 .agents/skills/mo-dev/scripts/mo-cgo-test -p 1/2 -count=1 -short -tags matrixone_test -timeout=12m -json [-race] [-overlay ...] -run '^TestIssue24971LockWaitBackpressureRecovery$' ./pkg/tests/issues/isolated;Connector 用同一 wrapper 跑完整包。原始命令、真实 SHA、JSONL/stderr、退出码和独立夹具差异已保存在本轮审计记录;native 输入未变化,由 wrapper 校验匹配产物后复用。

限制:当前协议中 hold 窗口证明 SQL data-phase backpressure 与恢复结果,不声称在此时观察到了 terminal send;channel-full terminal 契约由上述组件测试分别证明。本轮没有重建 v4.1.2/pre-#25273 作为 fail-before 负对照,没有扩大为全拓扑/全仓库/GPU 验证。#24971 当前已关闭,按已处理保留状态,不重复转测。

This branch was previously deployed

1 inactive deployment
ci — 82e7405f Deployed Oct 17, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants