Repository navigation
Description
Branch and commit
Reproduced on 4.2-dev at 6faa4f240f38c56e89866e7eb1845b0f4cf3ec0c (Go 1.27.1, darwin/arm64). The original incident was on a Linux CN running 5c16f56639.
Actual behavior and impact
When a file read needs a new buffer and the IO allocator returns ENOMEM, IOEntry.prepareData panics. The caller, ReadFromOSFile, has an error return. The panic happens before reading any file data.
In QA on 2026-11-23 (UTC+8), allocator diagnostics reported 65,530 process mappings against a limit of 65,530. At 17:44:14 the logtail subscription worker hit panic: cannot allocate memory while reading checkpoint metadata. The stack included ConsumeCheckpointEntries → CKPReader.ReadMeta → … → DiskCache.Read → IOEntry.ReadFromOSFile → IOEntry.prepareData. The CN process exited with code 2 at 17:44:18 and the container restarted at 17:44:22. The workload responsible for the mapping growth is still unknown.
Expected behavior
Return an error matching ENOMEM to the caller and leave the entry incomplete. A file read that already has enough buffer capacity should still succeed.
Isolated regression case
Place the following file at pkg/fileservice/io_entry_enomem_regression_test.go in the revision above. The test reads one byte and substitutes a test allocator. Run only this test since the allocator getter is package-wide.
go test -mod=readonly -count=1 -run '^TestReadFromOSFileAllocatorENOMEM$' -v ./pkg/fileserviceObserved output (abridged):
wanted returned ENOMEM, got panic=cannot allocate memory (allocations=1)
(*IOEntry).prepareData io_entry.go:121
(*IOEntry).ReadFromOSFile io_entry.go:59
--- PASS: TestReadFromOSFileAllocatorENOMEM/existing_buffer
--- FAIL: TestReadFromOSFileAllocatorENOMEM/needs_buffer
Go test source
package fileservice
import (
"context"
"errors"
"os"
"path/filepath"
"runtime/debug"
"syscall"
"testing"
"github.com/matrixorigin/matrixone/pkg/common/malloc"
)
type enomemReadAllocator struct{ calls int }
func (a *enomemReadAllocator) Allocate(uint64, malloc.Hints) ([]byte, malloc.Deallocator, error) {
a.calls++
return nil, nil, syscall.ENOMEM
}
func TestReadFromOSFileAllocatorENOMEM(t *testing.T) {
// Run this test in isolation because ioAllocator is package-wide.
fake := new(enomemReadAllocator)
original := ioAllocator
ioAllocator = func() malloc.Allocator { return fake }
t.Cleanup(func() { ioAllocator = original })
path := filepath.Join(t.TempDir(), "input")
if err := os.WriteFile(path, []byte("x"), 0600); err != nil {
t.Fatal(err)
}
read := func(t *testing.T, entry *IOEntry) error {
t.Helper()
f, err := os.Open(path)
if err != nil {
t.Fatal(err)
}
defer f.Close()
return entry.ReadFromOSFile(context.Background(), f, nil)
}
t.Run("existing_buffer", func(t *testing.T) {
entry := IOEntry{Size: 1, Data: make([]byte, 1)}
if err := read(t, &entry); err != nil || string(entry.Data) != "x" || fake.calls != 0 {
t.Fatalf("err=%v data=%q allocations=%d", err, entry.Data, fake.calls)
}
})
t.Run("needs_buffer", func(t *testing.T) {
entry := IOEntry{Size: 1}
defer func() {
if p := recover(); p != nil {
t.Fatalf("wanted returned ENOMEM, got panic=%v (allocations=%d)\n%s", p, fake.calls, debug.Stack())
}
}()
err := read(t, &entry)
if !errors.Is(err, syscall.ENOMEM) || fake.calls != 1 || entry.done {
t.Fatalf("err=%v allocations=%d done=%v", err, fake.calls, entry.done)
}
})
}Related work
#28736 and #28739 cover ENOMEM during mapping release and the allocator's recovery behavior. This case exercises the file-read caller when a subsequent allocation is refused. The unit test establishes the failure in that caller. The CN restart and the mapping count come from the separate QA incident.
Activity
iamlinjunhong commentedon Nov 23, 2026
Confirmed on upstream
mainate17d5541537d30252009a9a2d4c70ab5480d3bc3(darwin/arm64, Go 1.27.1). I ran the exact regression test from the issue body after building the native dependencies for that revision.cannot allocate memory.The stack was
ReadFromOSFile(line 56) →readFrom(line 64) →prepareData(line 126). Both branches convert the read-buffer allocation error into a panic. Please track bothmainand4.2-devhere and run the same regression on each fix. The main result is a local fileservice test. The CN process exit reported above was observed in QA on the deployed revision.main source at the failing line
Return fileservice read buffer allocation errors (#33129)
Ariznawlll commentedon Nov 24, 2026
结论
测试不通过。最新
4.2-dev的原始 ENOMEM 复现仍触发 panic;main的对应文件读取与资源释放定向验证已通过。两条分支的验收不能合并为整体通过,本次不关闭 Issue。关键证据
main@568f0f4fdee3c34373f27b04316a2adf7d32a78a、4.2-dev@9ed1645371c63ad2c417022de9e4d56db8697ecc。测试直接编译这些源码,未替换其他正在运行的 MO。TestReadFromOSFileAllocatorENOMEM。4.2-dev连续 3 次:existing_buffer通过、分配器调用数为 0;needs_buffer连续 3 次失败,分配器返回一次 ENOMEM 后,在IOEntry.prepareData的io_entry.go:121panic:cannot allocate memory。测试捕获 panic 后以 FAIL 退出,并非将 panic 当成功。main的同一原始用例,以及TestIOEntryReadBufferAllocation、TestLocalFSReadBufferAllocationRollback、TestLocalFSReadPublishesReusedDataOnSuccess,普通与-race均连续 3 次通过。断言覆盖返回 ENOMEM、不将失败 entry 标记完成、不消费文件偏移、部分分配资源释放、复用已有缓冲区,以及短读/转换失败的状态保持。go test -mod=readonly -count=3 -run '^Test(ReadFromOSFileAllocatorENOMEM|IOEntryReadBufferAllocation|LocalFSReadBufferAllocationRollback|LocalFSReadPublishesReusedDataOnSuccess)$' ./pkg/fileservice;main 再加-race。原始复现源码来自本 Issue,新增回归已在 main 修复 PR #33129 中,无另提主库测试 PR。待解决点
fileservice: preserve ENOMEM from disk cache reads (#33162)
XuPeng-SH commentedon Nov 24, 2026
补充 main 转测范围,保留现有 QA 负责人:PR #33162 已合入 main,merge
240df17666a179e69c98c2ea00c6668ca99be373。盘缓存读到 ENOMEM 时不再当普通未命中去对象存储再次分配。部分命中后失败会清除已释放的 vector-owned buffer 别名,避免原向量重试读到失效引用;短读等普通缓存错误仍回退。独立评审在早期 head
b1c00d1b的 11 项定向测试普通/race 通过,已有活动下载的 pin 释放用例 race 100 次;未过滤的全量普通/race 遇到基线也会出现的下载用例失败,不能当全量 race 通过。本轮未重跑合并 SHA。请在最新 main 验证盘缓存全文件/范围、混合批部分命中后 ENOMEM 同向量重试、资源 pin 与普通短读回退,并保留 Linux CN 映射耗尽事故另行验收。4.2-dev #33131 尚未合入,前次 4.2 定向失败仍有效;不能据此关闭工单。Ariznawlll commentedon Nov 24, 2026
main 验收结论
#33162 合入后的 main 已通过原始 ENOMEM 复现及新增盘缓存读取回归,按 main 的文件读取分配失败应返回错误而不是 panic 范围关闭本 Issue。依照本轮验收约定,修复尚未合入的 4.2-dev 不再作为本次关闭前置;这里不声称 4.2-dev 已修复。
精确版本与方法
240df17666a179e69c98c2ea00c6668ca99be373(fileservice: preserve ENOMEM from disk cache reads #33162,fileservice: preserve ENOMEM from disk cache reads)的源码归档。TestReadFromOSFileAllocatorENOMEM,并同场执行 Return fileservice read buffer allocation errors #33129/fileservice: preserve ENOMEM from disk cache reads #33162 的 7 个相关测试。-race均使用-count=3:每组 8 个顶层测试 × 3 = 24 次顶层 PASS,0 FAIL;两种模式最终均为ok github.com/matrixorigin/matrixone/pkg/fileservice。覆盖的实际断言
x;需要新 buffer 时分配器恰好调用一次,返回可errors.Is(...,syscall.ENOMEM)匹配的错误,entry.done=false,不再 panic。TestIOEntryReadBufferAllocation、TestLocalFSReadBufferAllocationRollback、TestLocalFSReadPublishesReusedDataOnSuccess;成功、短读和转换错误均保持相应状态与资源所有权。TestS3FSReadDiskCacheAllocationFailure的range和full两个子测试均通过;分配失败保留 ENOMEM,不把它当普通 cache miss 再去对象存储分配。TestS3FSReadDiskCacheShortReadFallsBack通过,确认修复没有把普通缓存短读也变成硬失败。TestDiskCacheAllocationFailureKeepsEarlierHitOwned、TestDiskCacheDownloadAllocationFailure通过,覆盖前序命中后的 ENOMEM 清理、同向量重试所有权及活动下载 reader pin 释放。范围边界
本关闭依据是确定性的文件读取/盘缓存 ENOMEM 注入和生产 fileservice 代码路径。没有复现 Linux CN 的 65,530 VMA 耗尽全过程,也没有把该测试写成映射增长来源已查明、生产压力或容器重启专项已通过;这些不属于本次 main 文件读取错误处理关闭结论。
Return fileservice read buffer allocation errors (#33131)