Repository navigation
Description
Bug Report
Summary
TPCC warehouse=1000 测试期间,CN 节点触发 panic: assignment to entry in nil map,发生在 pkg/frontend/mysql_cmd_executor.go 的 sanitizeNonFiniteFloatValue 函数中。
CI
- Run: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30143464491
- Namespace:
mo-main-commit-36f8b76c3-20260725 - MO commit:
36f8b76c398e31b4f763fc9b32af5591ee0e1060(main) - Pod:
nightly-regression-dis-tp-cn-qfszt - 时间: 2026-07-25 06:59:59 UTC
Panic Stack Trace
panic: assignment to entry in nil map
runtime.mapassign
/usr/local/go/src/internal/runtime/maps/runtime.go:208
reflect.mapassign0
/usr/local/go/src/runtime/map.go:254
reflect.mapassign
/usr/local/go/src/reflect/value.go:3746
reflect.Value.SetMapIndex
/usr/local/go/src/reflect/map.go:439
github.com/matrixorigin/matrixone/pkg/frontend.sanitizeNonFiniteFloatValue
/go/src/github.com/matrixorigin/matrixone/pkg/frontend/mysql_cmd_executor.go:5402 ← panic here
github.com/matrixorigin/matrixone/pkg/frontend.sanitizeNonFiniteFloatValue
/go/src/github.com/matrixorigin/matrixone/pkg/frontend/mysql_cmd_executor.go:5384 ← Struct recurse
github.com/matrixorigin/matrixone/pkg/frontend.sanitizeNonFiniteFloatValue
/go/src/github.com/matrixorigin/matrixone/pkg/frontend/mysql_cmd_executor.go:5381 ← Ptr recurse
github.com/matrixorigin/matrixone/pkg/frontend.sanitizeNonFiniteFloatValue
/go/src/github.com/matrixorigin/matrixone/pkg/frontend/mysql_cmd_executor.go:5388 ← Slice recurse
... (deeply nested recursive traversal)
调用路径:Struct → Ptr → Struct → Ptr → Slice → Struct → ... → Map → SetMapIndex → panic
问题分析
sanitizeNonFiniteFloatValue 递归遍历数据结构,将 NaN/Inf float 值替换为 0。在 Map 分支中:
case reflect.Map:
if v.IsNil() { // ← nil check
return
}
for _, key := range v.MapKeys() {
value := v.MapIndex(key)
...
v.SetMapIndex(key, copied) // ← line 5402: panics here
}有 v.IsNil() 检查但 SetMapIndex 仍然 panic,可能原因:
- 并发修改:另一个 goroutine 在遍历过程中修改了数据结构中的 map(设为 nil 或替换)
- 不可寻址的 map:map 作为 struct 的值字段(非指针),通过 reflect 获取时不可设置
- 嵌套 map 中的 nil:递归深入嵌套结构时遇到未初始化的内层 map
复现性
| Run | Commit | 时间 | nil map panic |
|---|---|---|---|
| 07-25 main ❌ | 36f8b76 | 06:59:59 | 有 |
| 07-23 main ✅ | f0ac2c9 | 全天 | 无 |
07-23 完全没有这个 panic。说明是 f0ac2c9bf..36f8b76c3 之间的某个 commit 改变了被遍历的数据结构(query plan/stats),引入了 nil map 字段。
影响
- 此 panic 被
export/batch_processor.go:180的 recover 捕获,没有导致 CN crash - 但说明
sanitizeNonFiniteFloatValue存在并发安全或防御性编程缺陷 - TPCC 测试本身的失败原因是
context canceled(另一个问题),nil map panic 发生在之后(06:59:59 vs 06:59:05)
建议修复
- 加防御检查:在
SetMapIndex前加v.CanSet()检查 - 加锁或拷贝:遍历前对数据结构做 deep copy,或在遍历时加读锁
- nil map 容错:在
SetMapIndex前再次检查 map 是否仍为 settable
case reflect.Map:
if v.IsNil() || !v.CanSet() {
return
}
// deep copy keys to avoid concurrent modification
keys := v.MapKeys()
for _, key := range keys {
value := v.MapIndex(key)
if !value.IsValid() {
continue
}
copied := reflect.New(value.Type()).Elem()
copied.Set(value)
sanitizeNonFiniteFloatValue(copied, seen)
if v.CanSet() {
v.SetMapIndex(key, copied)
}
}
Activity
XuPeng-SH commentedon Jul 25, 2026
Root cause is now identified.
The introducing change is #25843 (
b8a190a10ce, merged 2026-07-23), not #24643 alone. #25843 changedNewJsonPlanHandlerfrom eagerly callingh.Marshal(ctx)duringRecordExecPlanto retainingmarshalHandlerand serializing later in asynchronous statement export.ExplainDatastill shallow-copiesPhyPlan, soPhyOperator.OpStatsremains shared with the compile graph. The execution path callsRecordExecPlanand thenCompile.Release(); release/reuse can resetOperatorStats(including mutable maps) before deferredMarshalruns. The sanitizer added in #24643 then mutates a stale/shared map viaSetMapIndex; under TPCC concurrency, reset/reuse betweenIsNilandSetMapIndexproducesassignment to entry in nil map.Why it appeared only now: #24643 had existed with eager serialization before
Compile.Release; #25843 changed the object lifetime/timing and exposed the race.Fix direction: deep-copy
PhyPlanbefore retaining it for deferred marshal, includingOperatorStatsmaps andBackgroundQueries, and add a regression test that releases/resets the original plan before deferredMarshal.OperatorMetricsis the most likely map involved, but the retained CI artifacts do not prove the exact map field; the ownership/lifetime root cause is confirmed.fix: snapshot async execution plans (#26177)
XuPeng-SH commentedon Jul 26, 2026
should be fixed
Ariznawlll commentedon Jul 26, 2026
测试中
fix(tae): align late aobject visibility with parent txn (#26180)
[-]panic: assignment to entry in nil map in sanitizeNonFiniteFloatValue (TPCC warehouse=1000)[/-][+][Bug] panic: assignment to entry in nil map in sanitizeNonFiniteFloatValue (TPCC warehouse=1000)[/+]Ariznawlll commentedon Jul 28, 2026
验证结果
#26177 已于 07-26 合入,修复后最近 3 次 main nightly TPCC warehouse=1000 均通过:
Panic 已不再出现,可以 close 了。
fix: snapshot async execution plans (matrixorigin#26177)
fix(tae): align late aobject visibility with parent txn (matrixorigin…
fix: snapshot async execution plans (matrixorigin#26177)
fix(tae): align late aobject visibility with parent txn (matrixorigin…
fix: snapshot async execution plans (matrixorigin#26177)
fix(tae): align late aobject visibility with parent txn (matrixorigin…