Skip to content

[Bug]: off-heap vector buffers leak on v4.2.1 clone and transaction error paths #31690

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

v4.2.1-hotfix and release/v4.2.1-hotfix-20261026. The relevant source files are identical to the v4.2.1 tag on both branches.

Commit ID

Reproduced against v4.2.1 commit d2393868a7aaa6343518d80849fe4696aa3577e9. At inspection, v4.2.1-hotfix was at 115c227239c65dfe36e14379d958033bf274f8f4 and release/v4.2.1-hotfix-20261026 at f6a27941d7185e3b406f7d45326ff9c86a9d1ff7.

Other Environment Information

  • Linux amd64, Go 1.26.4.
  • Diagnostic tests used the v4.2.1 source and locally available third-party native libraries; the provenance of those libraries was not fully verified.

Actual Behavior

Three paths lose ownership of vector resources:

  1. Vector.CloneWindowTo sets the destination's data to nil for a constant NULL source without freeing its existing owned buffer. In a real off-heap mpool test, a 10,485,760-byte allocation remained accounted after closing the destination and running Go GC; freeing the saved original buffer reduced the count to zero.
  2. getRowsByPK and its callers return on certain errors before registering rowIDs.Close(). A deterministic injected duplicate-check error returned a vector still occupying one Small pool slot with 24 bytes retained. Closing it released the slot. The second caller at line 1242 has the same cleanup ordering.
  3. prepareApplyANode borrows a new vector when startOffset == 0, but error returns do not close it before ownership transfers to node.data. An injected schema mismatch left one pool slot in use with 24,576 bytes retained, using a pool slot seeded with a buffer.

Small-pool vectors use off-heap allocations. A separate pool diagnostic showed that an unclosed vector retained 10,485,760 bytes after Go GC, while Close() released it. The actual growth rate and production RSS impact of paths 2 and 3 have not been measured.

Expected Behavior

Each owned buffer or borrowed pool vector is released or transferred exactly once, including on error. Successful behavior and the existing write-write conflict handling remain unchanged.

Steps to Reproduce

  1. At the stated v4.2.1 commit, allocate an off-heap destination vector with a 10 MiB buffer from a real mpool. Clone a non-empty constant NULL vector into it using CloneWindowTo, close both vectors, run GC, and inspect CurrNB(). Keep the original buffer reference in the test so it can be freed afterward. The count remains 10 MiB until the saved buffer is explicitly freed.
  2. Create a table with a visible object whose GetDuplicatedRows returns an injected error. Call getRowsByPK with a Small vector pool and inspect the returned vector and pool.Used(true) before closing it. It remains borrowed on error; the callers return before closing it for the relevant errors.
  3. Seed a Small pool slot with an allocated rowid buffer and return it. Call prepareApplyANode with startOffset == 0 and an appender whose IsSameColumns returns false. After the schema-change error, inspect pool.Used(true): the seeded slot remains in use.

Additional information

Focused diagnostic tests for all three paths passed against the stated tag. The tests for paths 2 and 3 use injected dependencies; they do not measure production frequency. The separate replaceCommitts/Dup failure candidate has not been validated and is outside this report.

Activity

  1. added
    kind/bug
    on Oct 29, 2026
  2. added
    severity/s0
    and removed on Oct 29, 2026
  3. added 3 commits that reference this issue on Oct 29, 2026
    3391c68
    1cea057
    260678b
  4. XuPeng-SH commented on Oct 29, 2026

    @XuPeng-SH
    ContributorAuthor

    QA handoff for merged #31704 (1cea057047b7485736421842612c38d5667152ef): this isolated QA run inspected the source and issue history but did not run current-head functional tests or live SQL because the existing resource guard left insufficient headroom. Please verify const-NULL clone ownership, buffer leases and pool accounting. Author-reported PR tests are separate evidence and are not results of this QA run.

  5. MatrixAdventurer commented on Oct 30, 2026

    @MatrixAdventurer
    Contributor

    核实结论:已修复可关闭。

    根因(pkg/container/vector/vector.go 的 clone_window_to 复用向量借入数据路径,约 L10810):克隆常量 NULL 窗口数据时未释放目标向量借入的 dataLease、未把 cantFreeData 置空,复用池向量随事务积累导致内存增长。修复已在三条涉及分支合入:main #31704(2026-10-29)、4.2-dev #31699、4.2.1-hotfix #31693。

    证据:回归测试 TestVectorAllocationAccountConstNullCloneReuse、TestCloneWindowToConstNullReleasesDataLease(vector_test.go / buffer_lease_test.go)、TestCloneConstNullWithReusedPoolVector、TestCloneConstNullPoolAllocationLimit(vector_pool_clone_test.go)覆盖借入释放与池化复用,normal+race 均过;PR 自述复现脚本内存曲线由增长变为约 97MB 平坦。

    还缺:无本轮可见缺口。

    @Ariznawlll 请确认后关闭。本操作由LW授权的MOI智能体提交

  6. slyunnn commented on Nov 2, 2026

    @slyunnn

    Regression and extended verification for #31690 (2026-11-02)

    Verification Environment

    • Main fetched before QA: ea184ad90624ae3dba8ced628ac019271a6c309c — fix: authorize exclusive SELECT lock targets (#31978).
    • Clean native build, macOS/arm64, Go 1.27.1, verified native-library provenance. Executable build metadata and runtime git_version() identify ea184ad906.
    • Fresh topology: 2 CN / 1 TN / 1 Log service / Proxy. Proxy localhost:6001, CN1 localhost:16001, CN2 localhost:16002 were reachable and each ran the constant-NULL and transaction-recovery SQL controls through PyMySQL/MySQL text protocol.
    • The reported internal allocation and injected failure paths were tested directly in Go, not inferred from SQL health checks or process RSS.

    What Was Covered

    • OK — Original off-heap ownership boundary: 20 allocations of at least 10 MiB, each cloned from a non-empty constant-NULL source. After destination release and Go GC, mpool.CurrNB() returns to 0 every iteration.
    • OK — Owned capacity remains reusable until release; allocation-account metadata is released. Fixed-width/variable-width vectors, nil-mpool clone, legacy aliases, data-only leases and shared data/area leases are covered by the maintained tests.
    • OK — Pool reuse and allocation-limit eviction: vectors return to the pool and final destruction releases tracked memory. All 6 directly affected clone/accounting/lease/pool tests also passed individually with -race -count=100.
    • OK — Snapshot duplicate-check error injection returns no retained result and no extra checked-out pool vector over 100 iterations. Existing incremental-error and write-write-conflict tests pass, preserving the intentional conflict-result handoff.
    • OK — Seeded rowid buffer with schema mismatch, appender lookup failure and canceled context: each error path repeated 100 times; pool usage returns to 0, retained reusable bytes remain bounded, append lock bookkeeping balances, and pool destruction frees the remaining allocation. Normal and race modes passed.
    • OK — Real SQL at all three endpoints: constant-NULL projection, duplicate-key failure, rollback, subsequent commit and exact row readback; fixtures removed.
    • Not covered — A production RSS/growth-rate measurement, release-branch executable reruns, GPU mode or long-running soak. No result for those modes is claimed.

    Findings

    Main fix: PR #31704, merge 1cea057047b7485736421842612c38d5667152ef — fix(vector): preserve const-null clone backing ownership, included in this main snapshot. Owned backing remains reachable for reuse/free; borrowed data drops its own lease reference without releasing independent area ownership.

    The transaction paths have been refactored on main: non-conflict errors close candidates in the callee; write-write conflicts transfer the result to a caller that closes it; a newly borrowed append rowid vector is either closed on error or transferred into node data on success. Direct error injection validated the current paths rather than assuming old line numbers still identify the owner.

    Ownership boundary Terminal owner / bound Result
    Owned clone buffer / allocation account Destination release, reusable capacity remains tracked until then Verified
    Borrowed data and shared area Independent reference-counted lease releases Verified
    Pooled transaction vectors Error cleanup or explicit caller/node transfer; pool destruction releases retained capacity Verified

    The tested error branches also release the append lock; no broader distributed-liveness claim is made. No new product defect was confirmed.

    Related backports are merged: #31699, 260678bace0177678255089a23d0fe7d54cfc745, into 4.2-dev; #31693, 3391c6844e95d1bb27a647b18f48f7c3a5ba1695, into release/v4.2.1-hotfix-20261026. Merge status is not evidence that this QA run executed those branch binaries.

    MOTR / BVT Coverage

    • Full pkg/container/vector, pkg/vm/engine/tae/containers, and pkg/vm/engine/tae/txn/txnimpl packages passed in normal and race modes.
    • Additional internal fault/accounting probes passed using temporary Go test overlays; tracked source was not modified. Those probes are local QA evidence, not newly scheduled CI coverage.
    • SQL controls ran serially with isolated databases. Package tests use their own fixtures; repeated race stress selected one exact test at a time. MOTR scheduling is not an engine-parallelism proof.
    • No duplicate SQL-only MOTR case was added: SQL cannot deterministically inject these internal errors or assert exact allocator/pool ownership. Existing maintained unit tests directly own the clone and pool contracts. No source change, commit or PR was made for this QA run.

    Final Conclusion

    Fixed on the tested main snapshot, with the original ownership failures covered by direct allocation and fault-injection evidence. Large-row-count regression is not required. A memory-boundary regression was required and completed using the reported 10 MiB scale and repeated error/reuse checks; arbitrary row growth or a TKE performance run would not improve this ownership oracle. This conclusion does not certify unexecuted release-branch binaries or production RSS behavior.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions