Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
a5eb8b6 (surfaced on a PR branch merged up to this commit)
Other Environment Information
- Hardware parameters: GitHub Actions runner
amd64-mo-shanghai-8c16g - OS type: Linux / x86_64
- Others: Go 1.26.4,
go test -race
Actual Behavior
The race detector reports a data race in the mo_table_stats background collector, which fails the whole pkg/tests/dml test binary — any test in that package can be the reported victim, whatever it was doing.
WARNING: DATA RACE
Write at 0x00c035a32f78 by goroutine 11621:
disttae.(*dynamicCtx).alphaTask.func2()
pkg/vm/engine/disttae/mo_table_stats.go:1910
github.com/panjf2000/ants/v2.(*goWorker).run.func1()
Previous read at 0x00c035a32f78 by goroutine 11535:
runtime.growslice()
disttae.getChangedTableList()
pkg/vm/engine/disttae/mo_table_stats.go:2985
disttae.(*dynamicCtx).prepare()
pkg/vm/engine/disttae/mo_table_stats.go:1698
disttae.(*dynamicCtx).tableStatsExecutor()
pkg/vm/engine/disttae/mo_table_stats.go:1634
Expected Behavior
d.tableStock.tbls is mutated by pool workers and grown by the producer concurrently; neither should race.
Steps to Reproduce
Timing dependent — it fires on loaded CI runners. Observed on Matrixone CI / UT Test on Ubuntu/x86:
https://github.com/matrixorigin/matrixone/actions/runs/33016152574/job/98348677062
I could not reproduce it locally: go test -race -count=6 -run TestDataBranchPickRetestRegressions ./pkg/tests/dml/ is clean on both main and the PR branch on an idle machine.
Analysis
The lock in tableStatsExecutor protects only the slice header, not the backing array:
// mo_table_stats.go:1638-1641
d.Lock()
tbls := d.tableStock.tbls[:] // header copy; same backing array
d.Unlock()
d.alphaTask(newCtx, service, tbls, "main routine")alphaTask keeps tblBackup = tbls[:] (:1767) and dispatches to an ants pool whose workers write into the elements after the lock is released:
// mo_table_stats.go:1909-1911
tbls[i].pState = pState
tbls[i].errChan = errQueue
d.tblQueue <- tbls[i]Meanwhile prepare() appends to the same slice without the lock:
// mo_table_stats.go:1697-1702
err = getChangedTableList(..., &d.tableStock.tbls, ...)
// :2985
*pairs = append(*pairs, tp) // growslice reads/copies the old arraySo a worker writes tbls[i] while append is copying that array — the reported write/read pair. d.tableStock.tbls[i].pState = nil and the truncation at :1587-1591 are a third writer of the same elements.
Two candidate fixes, depending on the intended ownership:
- Give
alphaTaskits own copy of the element slice (append([]tablePair(nil), tbls...)) so the collector's array is never shared with the pool workers; or - Extend the lock to cover the whole produce/consume cycle, so
prepare()cannot append while a previousalphaTaskis still in flight.
The first keeps the lock scope small and matches what tblBackup seems to intend.
Impact
Beyond turning -race CI red at random, the same interleaving without the detector means a worker's pState / errChan write can land in an array that append has already abandoned — the stats task silently loses that table's partition state, or writes it where nothing reads it.
Note
Found while investigating a CI failure on PR #27609, which touches only pkg/catalog, pkg/sql/colexec/external, pkg/sql/util/csvparser and pkg/sql/plan/query_builder.go — nothing in disttae. Filing separately because it is independent of that PR.
Activity
XuPeng-SH commentedon Oct 23, 2026
Static review of PR #30926 head
6f3a042b8e192f33343a78680f9e633c0d8060f9found an overlap case worth covering alongside the detached-slice race fix.The PR and this issue both describe concurrent
tableStatsExecutorrounds as possible. Each round snapshotsd.tableStock.tbls, butspecialTo/specialFromand cleanup remain shared. If round A is collecting while round B runsprepare, B overwrites those timestamps and snapshots the shared stock; when A returns, it reads B's timestamps inupdateSpecialStatsStartand thencleanTableStock()clears the shared stock. A can therefore advance the persisted start to B's end before B has successfully completed its own batch; if B subsequently times out/errors, that interval may be skipped on the next collection. The current regression drivesrunStatsCollectionRounddirectly and checks that collector-written stock survives, but does not exercise the executor's progress update and final cleanup ordering.Could you add a deterministic two-executor test (including B timing out/failing after A completes) and serialize each round's snapshot, progress update, and cleanup or otherwise make progress ownership round-local? This is a static concurrency-path finding; I have not run it locally.
gouhongshen commentedon Oct 23, 2026
PR #30926 is trying to fix this issue.
XuPeng-SH commentedon Oct 23, 2026
QA follow-up for PR #30926 at head
6f3a042b8e192f33343a78680f9e633c0d8060f9: the detached slice snapshot addresses the reported backing-array data race, but the executor still keeps the time window and cleanup state shared ind.tableStock.A remaining overlapping-executor failure sequence appears possible: round A prepares window W1 and starts alpha; round B prepares W2 while A is in flight, replacing
specialFrom/specialToand adding B's tables to the shared stock; A then completes successfully and updates the shared watermark using W2 before B has completed, and A'scleanTableStock()can clear B's pending stock. If B subsequently errors/cancels, W2 may already be skipped. The new regression exercises the production alpha handoff against a concurrent stock mutation, but it does not run two full executor lifecycles or assert watermark/stock preservation across this completion/failure ordering.Please isolate the progress window and cleanup ownership per executor round (or otherwise serialize the overlapping rounds), and add a deterministic test where A completes while B is blocked and then fails/cancels; assert the watermark does not pass B's unfinished window and B's pending tables are retained.
XuPeng-SH commentedon Oct 23, 2026
PR #30926 head refresh —
b2992ed7f7d0c057729ff7ff868a3179a0e2770f(2026-10-23)The PR's latest sync merged main; its effective change remains the same two files (
mo_table_stats.goandmo_table_stats_test.go). Comparing the relevanttableStatsExecutor/stock code at the approved head6f3a042and current head shows the detached snapshot is present, but the round still uses sharedspecialFrom/specialToandcleanTableStock()still clears the shared stock on executor exit. I do not see a change addressing the overlapping-round progress/cleanup sequence described in the earlier comments here.This remains a static concurrency concern, not a reproduced failure. The existing approval and its race-detector evidence validate the slice-alias race fix on
6f3a042, not the separate two-executor watermark/cleanup case at this synced head. Please either establish that executor admission makes the overlap impossible (with the scheduler/heartbeat ordering evidence) or add a deterministic overlapping-round failure test and isolate/serialize progress and cleanup ownership. No new issue opened.Post-merge verification status — 2026-10-23
PR #30926 is now merged at
f8c872001603fed3d23784e1ada26f9a2d8f4fba(PR headb2992ed7f7d0c057729ff7ff868a3179a0e2770f). The merged diff still leaves the shared progress window and cleanup sequence described above. The combined status has no checks; the only workflow run found on the head is unrelated Iceberg Connector E2E. I could not run a local harness because this workspace has no MatrixOne checkout or Go runtime. This is not independent reproduction; issue #27702 remains open and assigned to gouhongshen pending resolution of this follow-up.fix(disttae): hand alpha stats workers a detached table stock snapshot (
gouhongshen commentedon Oct 23, 2026
PR #30926 has merged and is awaiting manual validation. The issue remains open.