Repository navigation
Description
Description
DATA BRANCH DIFF ... OUTPUT FILE can return a successful result even when the target file service reports an error after it has consumed all streamed data.
This affects both file-output implementations:
- the non-
MutableFileServicepath implemented bynewSingleWriteAppender; - the
MutableFileServicepath, whosereleasefunction discardsmut.Close()errors.
Code path
On current main (2eb7f523e5a10f352d3e258183ed8440510388de):
newSingleWriteAppenderstartstargetFS.Writein a worker and stores its final error indone.- If the file service reads the complete pipe and only then returns an error, all producer-side
writeFilecalls have already succeeded. releasereceives the final error but only invokesonError; its signature has no error result, so the caller cannot observe the failure.satisfyDiffOutputOptsetssucceeded = trueand adds the success result row before the deferredreleaseruns.
The mutable path has the same ordering problem: every mut.Append may succeed, while the deferred release executes _ = mut.Close(). Mutator.Close() performs the final Sync and close operations and can return an error, but that result is discarded after the statement has already been marked successful.
Relevant locations:
pkg/frontend/data_branch_output.go:899-905pkg/frontend/data_branch_output.go:990-992pkg/frontend/data_branch_output.go:1679-1689pkg/frontend/data_branch_output.go:1701-1753
Reproduction
A package-level test used a FileService wrapper whose Write method:
- fully reads every
ReaderForWriteentry; - returns a deterministic final write error afterward.
Observed in 3/3 runs:
writeFile("BEGIN;\n")returnednil;writeFile("COMMIT;\n")returnednil;release()observed the final error only through the cleanup callback;- no error value was available to propagate to the SQL statement.
Test command:
go test ./pkg/frontend -run '^TestAuditDataBranchOutputLateWriteFailureIsNotReturned$' -count=3 -v
Expected behavior
The final file-service write result should be awaited before the statement is marked successful. A final write error should be returned to the SQL caller, and the partial output should be cleaned up.
Actual behavior
The final write/close error is discarded by release(). The non-mutable path runs its cleanup callback, while the mutable path does not receive the close error at all; in either case the SQL statement can still report a successful file path/result row.
Activity
fix(frontend): surface data branch file finalization errors (#26505)
gouhongshen commentedon Aug 2, 2026
fixed
Ariznawlll commentedon Aug 4, 2026
测试版本
main37694c49f2f450f7aa7bb5560279d7ab7007c05d原问题验证
使用
lateFailingWriteFS完整消费每个ReaderForWrite,在生产端BEGIN;、COMMIT;均写入成功后返回mock late write failure,复现原 issue 的 late-write failure 边界。修复后 finalizer 将该错误返回调用方;SQL 层satisfyDiffOutputOpt返回原错误,结果集行数为 0,并执行预清理和失败输出清理。7 个定向用例使用-count=3连续执行,共 21 次通过。Happy Path 覆盖
BEGIN;\nCOMMIT;\n。Unhappy Path 覆盖
FileService.Write完整消费 stream 后返回错误:finalizer 返回internal error: mock late write failure。Mutator.Close()返回mock mutator close failure:错误传递给调用方,Close精确调用 1 次。FileService.Write立即失败:release 返回原始mock write failure。白盒验证
-count=3:21/21 通过。-race -count=20:140/140 通过,无 race 报告。pkg/frontendCGO UT:通过,耗时 15.711s。回归测试
FileService.Write完整消费后或Mutator.Close时注入,公开 SQL/BVT/motr 无法确定性制造,因此回归归入 frontend UT。测试证据
.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -run '<7 exact tests>' -count=3 -v,结果 21/21 通过。.agents/skills/mo-dev/scripts/mo-cgo-test -race ./pkg/frontend -run '<7 exact tests>' -count=20,结果 140/140 通过。.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -count=1,结果ok github.com/matrixorigin/matrixone/pkg/frontend 15.711s。测试结论
测试通过。
fix(frontend): surface data branch file finalization errors (matrixor…
fix(frontend): surface data branch file finalization errors (matrixor…
fix(frontend): surface data branch file finalization errors (matrixor…