Repository navigation
Description
Summary
In the freetier-01 production environment, a betaTask goroutine in mo_table_stats.go was stuck in a select statement for 46.5 hours, holding an open transaction that could never be cleaned up.
Environment
- Cluster: freetier-01 (prod)
- Pod: freetier-01-s2-56c954c888-cn-qxjh7
- MO version: production build deployed ~3 days ago
Symptoms
- Leak checker reported every 20 minutes:
ERROR cn-service found leak txn txn-id: 0acdcbd9d5f822ce18bd902a36285465 create-at: 2026/06/30 15:03:02 (46+ hours ago) session: migrate-goRoutineId 0 lockWaitTimeout: 31536000000000000 (~1 year)
Root Cause
Stuck goroutine (from ETL leakcheck profile)
goroutine 997023 [select, 2793 minutes]: <-- 46.5 hours!
github.com/matrixorigin/matrixone/pkg/vm/engine/disttae.(*dynamicCtx).betaTask(...)
mo_table_stats.go:2029 <-- stuck in select
github.com/matrixorigin/matrixone/pkg/vm/engine/disttae.initMoTableStatsConfig.func1.8.1()
mo_table_stats.go:464
Code path (mo_table_stats.go)
betaTask is a long-lived goroutine that processes table statistics across multiple alphaTask rounds:
func (d *dynamicCtx) betaTask(ctx context.Context, service string, eng engine.Engine) {
for {
select {
case <-ctx.Done(): // exit on context cancellation
return
case tbl := <-d.tblQueue: // receive next table to process
// process stats...
}
// *** NO idle timeout, NO heartbeat ***
}
}The select only has two cases:
ctx.Done()— butturn2SysCtx()only wraps with a tenant value, does NOT create a cancellable contextd.tblQueue— fed byalphaTask, which is called bytableStatsExecutorperiodically
Why it gets stuck permanently
After alphaTask finishes feeding tables and tableStatsExecutor resets its ticker (executeTicker.Reset(d.conf.UpdateDuration)), betaTask enters the select and waits for the next round. If the executor is blocked (e.g. prepare() hangs on a SQL query) or the stats task is disabled (checkMoveOnTask() returns true), betaTask will wait indefinitely with no self-recovery mechanism.
Transaction leak chain
alphaTask → subscribeTable() → creates txn (0acdcbd9...)
→ PartitionState sent to betaTask via d.tblQueue
→ betaTask processes, then enters select waiting for more
→ 46.5 hours pass with no new data
→ goroutine still alive → txn never cleaned up
→ lockWaitTimeout=1 year → not killed by timeout
Suggested Fix
- Add idle timeout to betaTask select:
select {
case <-ctx.Done():
return
case tbl := <-d.tblQueue:
// process...
case <-time.After(maxIdleDuration): // NEW: idle timeout
return // alphaTask will relaunch on next round
}-
Use cancellable context for betaTask: wrap with
context.WithCancelso whentableStatsExecutorexits, betaTask is properly cancelled. -
Reduce migrate session lockWaitTimeout: 1 year is unreasonable; use a sensible default.
Attached
qxjh7_leakcheck_goroutine_20260702.txt.gz— Full goroutine dump from the ETL leakcheck profile (750KB decompressed). Search forgoroutine 997023to find the stuck goroutine.
Activity
aptend commentedon Jul 2, 2026
ETL leakcheck goroutine dump attached:
qxjh7_leakcheck_goroutine_20260702.txt.gz
goroutine 997023to find the stuck betaTask (46.5h in select)mo_table_statsfor all related goroutinesaptend commentedon Jul 6, 2026
Update after re-checking the dump/log correlation:
The current evidence is not enough to prove that the leaked txn is stuck in
mo_table_stats.betaTask.What we can confirm from the attached goroutine dump:
This is a long-lived table stats background goroutine. The
betaTaskcode is expected to stay in aselectwaiting for eitherctx.Done()ord.tblQueue, so a long[select]duration alone does not prove it is stuck or related to the leaked txn.The leaked txn log contains:
However, these values do not appear in the attached goroutine dump, and there is no reliable join from this txn/session/connection to
goroutine 997023.One important finding: the
goRoutineIdprinted in frontendsession_infocomes fromgithub.com/petermattis/goid, while goroutine dump ids come from the runtime stack header (goroutine N [...]). Thegoidpackage reads Go runtime internalg.goidlayout directly, and this can become unreliable when the Go runtime layout changes. In local verification,go test github.com/petermattis/goidfails with a mismatched id. That means the loggedgoRoutineIdcannot currently be trusted as a stable key to match against goroutine dump ids.Suggested follow-up:
mo_table_stats.betaTaskcaused the txn leak.runtime.Stack(buf, false), at low-frequency points such asNewRoutine/ migration begin and keep the cached value.This may add a small cost if done via
runtime.Stack, so it should stay cached and should not be recomputed for every log line.fix: align frontend goroutine id with runtime dump (#25497)
fix: align frontend goroutine id with runtime dump (matrixorigin#25497)
fix: align frontend goroutine id with runtime dump (matrixorigin#25497)
fix: align frontend goroutine id with runtime dump (matrixorigin#25497)