Skip to content

[Bug]: DATA BRANCH DIFF OUTPUT FILE can report success after a late write failure #26054

Closed

Description

@Ariznawlll

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-MutableFileService path implemented by newSingleWriteAppender;
  • the MutableFileService path, whose release function discards mut.Close() errors.

Code path

On current main (2eb7f523e5a10f352d3e258183ed8440510388de):

  1. newSingleWriteAppender starts targetFS.Write in a worker and stores its final error in done.
  2. If the file service reads the complete pipe and only then returns an error, all producer-side writeFile calls have already succeeded.
  3. release receives the final error but only invokes onError; its signature has no error result, so the caller cannot observe the failure.
  4. satisfyDiffOutputOpt sets succeeded = true and adds the success result row before the deferred release runs.

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-905
  • pkg/frontend/data_branch_output.go:990-992
  • pkg/frontend/data_branch_output.go:1679-1689
  • pkg/frontend/data_branch_output.go:1701-1753

Reproduction

A package-level test used a FileService wrapper whose Write method:

  1. fully reads every ReaderForWrite entry;
  2. returns a deterministic final write error afterward.

Observed in 3/3 runs:

  • writeFile("BEGIN;\n") returned nil;
  • writeFile("COMMIT;\n") returned nil;
  • 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

  1. added this to the MO-202607 milestone on Jul 23, 2026
  2. added
    kind/bug
    on Jul 23, 2026
  3. added theissue type on Jul 23, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Jul 31, 2026
  5. added a commit that references this issue on Jul 31, 2026
    a7a04b4
  6. gouhongshen commented on Aug 2, 2026

    @gouhongshen
    Contributor

    fixed

  7. added and removed
    severity/s0
    on Aug 2, 2026
  8. Ariznawlll commented on Aug 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:37694c49f2f450f7aa7bb5560279d7ab7007c05d
    • 部署方式:macOS arm64,隔离工作树,MatrixOne CGO frontend package UT
    • 测试日期:2026-08-04

    原问题验证

    使用 lateFailingWriteFS 完整消费每个 ReaderForWrite,在生产端 BEGIN;、COMMIT; 均写入成功后返回 mock late write failure,复现原 issue 的 late-write failure 边界。修复后 finalizer 将该错误返回调用方;SQL 层 satisfyDiffOutputOpt 返回原错误,结果集行数为 0,并执行预清理和失败输出清理。7 个定向用例使用 -count=3 连续执行,共 21 次通过。

    Happy Path 覆盖

    1. non-mutable 正常写入路径成功完成 finalization,输出文件内容精确为 BEGIN;\nCOMMIT;\n。
    2. 正常 worker pool 创建、写入和释放均成功,没有错误成功行丢失或输出内容缺失。

    Unhappy Path 覆盖

    1. non-mutable FileService.Write 完整消费 stream 后返回错误:finalizer 返回 internal error: mock late write failure。
    2. SQL 层 late-write failure:没有添加成功结果行,失败路径调用文件删除清理;writer 终止后再执行 cleanup。
    3. mutable Mutator.Close() 返回 mock mutator close failure:错误传递给调用方,Close 精确调用 1 次。
    4. FileService.Write 立即失败:release 返回原始 mock write failure。
    5. nil worker 和已释放 worker 的 submit 失败:构造阶段返回错误,没有进入伪成功路径。

    白盒验证

    • 7 个定向 UT 使用普通模式 -count=3:21/21 通过。
    • 同一组用例使用 -race -count=20:140/140 通过,无 race 报告。
    • 完整 pkg/frontend CGO UT:通过,耗时 15.711s。

    回归测试

    • 修复及 UT:PR #26505
    • 测试文件:pkg/frontend/data_branch_output_test.go
    • 该故障必须在 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。

    测试结论

    测试通过。

  9. added 3 commits that reference this issue on Sep 17, 2026
    93918ce
    f0bdca3
    6157815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions