Repository navigation
Description
Summary
FinalizeCommitWithUnknownResult never calls delTransaction(), causing permanent workspace, offheap batch vectors, quota, and cached metadata to leak indefinitely when a commit encounters ErrTxnUnknown. The leak persists until CN process restart.
Severity: High
Root Cause
There is a clear asymmetry between the three finalization paths:
| Path | Calls delTransaction()? |
Cleans workspace/batch/quota? |
|---|---|---|
FinalizeCommit() |
✅ Yes (line 2148) | ✅ |
Rollback() |
✅ Yes (line 2236) | ✅ |
FinalizeCommitWithUnknownResult() |
❌ No (line 2156–2158) | ❌ |
Code comparison
// disttae/txn.go - FinalizeCommit (line 2143-2148):
func (txn *Transaction) FinalizeCommit(context.Context) {
if txn.isCCPRTxn... { ... }
txn.delTransaction() // ✅ cleans up
}
// disttae/txn.go - FinalizeCommitWithUnknownResult (line 2150-2158):
func (txn *Transaction) FinalizeCommitWithUnknownResult(context.Context) {
if txn.isCCPRTxn... { ... }
// Comment says: "Keep workspace/object-stat metadata intact"
// txn.delTransaction() is NEVER called ❌
}What delTransaction() actually releases
| Resource | Type | Cleanup |
|---|---|---|
writes[i].bat |
batch + offheap C-malloc'd vectors | bat.Clean(mp) → vec.Free(mp) → mpool.Free → C.free |
tableCache / tableOps / databaseOps |
maps/slices | set to nil (GC) |
compactWorker |
goroutine pool | Release() |
extraWriteWorkspaceThreshold |
engine quota | engine.ReleaseQuota() |
deletedBlocks |
slice | set to nil |
None of these are freed in the ErrTxnUnknown path.
Full call chain
Commit() → doWrite() → defer {
if ErrTxnUnknown {
FinalizeCommitWithUnknownResult() // never cleans up
return // Rollback is NOT called either
}
}
→ closeLocked() → ClosedEvent → closeTxn()
// Only removes txnOperator from txnClient.activeTxns
// The disttae Transaction object and all its resources persist
Trigger conditions
- Commit RPC times out (network partition, TN restart)
- TN returns
ErrTxnUnknown(uncertain commit outcome) - CN calls
FinalizeCommitWithUnknownResultintending to preserve workspace for potential S3 GC
Impact
- Offheap (C heap) memory leaks: batch vectors allocated via
mpoolwithoffHeap=true→C.mallocmemory never freed until process exit - Quota leak:
extraWriteWorkspaceThresholdquota permanently consumed - Silent accumulation: no observability or timeout-driven cleanup
- Risk scenario: long-running CN process with intermittent network issues → hundreds of MB to GB of leaked offheap memory over days/weeks
Suggested Fix
Add either:
-
A timeout-driven cleanup: If
FinalizeCommitWithUnknownResulthas been unresolved for N minutes, forcibly calldelTransaction()to release resources. -
An explicit cleanup trigger: Allow the caller to signal that the unknown result has been resolved (either committed or aborted externally), at which point
delTransaction()is called. -
Defensive partial cleanup: At minimum, call
delTransaction()on CN shutdown or after confirming the commit cannot be recovered.
Related
- CN Transaction Rollback: resource leak, delayed waiter notification, and abortC signal loss #25195 — previously reported Rollback resource management issues in
service_cn_handler.go - Double-check report confirmed this is the only real leak (two other suspected issues were disproven)
Activity
fix(txn): finalize unknown commits without rollback GC (#25582)
aptend commentedon Jul 13, 2026
fixed
fix(txn): finalize unknown commits without rollback GC (matrixorigin#…
fix(txn): finalize unknown commits without rollback GC (matrixorigin#…
fix(txn): finalize unknown commits without rollback GC (matrixorigin#…