Skip to content

[Bug]: AWS unknown-size empty write returns success without creating the object #29266

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

66da387

Other Environment Information

  • Hardware parameters:
  • OS type:
  • Others: code inspection of origin/main. No open issue covers this. [Feature Request]: multipart write data to stage. #18947 is a multipart feature request. MinIO and Aliyun Write send the reader to putObject. COS unknown-size non-seekable writes go through WriteMultipartParallel, whose empty-reader path puts a zero-byte object.

Actual Behavior

AwsSDKv2.Write (pkg/fileservice/aws_sdk_v2.go 437–496) treats a nil sizeHint as a sequential multipart upload. It calls CreateMultipartUpload first. If the reader yields no bytes, the loop stops with num == 1 and the function return nil under the comment "no content".

That return is a success. The named err stays nil, so the defer that aborts the multipart upload does not run. CompleteMultipartUpload is not called, and there is no PutObject of a zero-byte object. The key does not exist, and the upload id remains.

S3FS.write (s3_fs.go 580–628) passes vector.size() through. IOVector.size (io_vector.go 165–176) returns nil when any entry has Size < 0. The ETL default parallel mode is ParallelOff (parallel_mode.go parseParallelMode(""), get.go etlParallelMode). With parallel mode off, an unknown-size stream uses storage.Write, which is this path.

Callers that then record success:

  • SELECT INTO OUTFILE / export (pkg/frontend/export.go 180–197, Close 270–287). Header off and zero rows closes the pipe without a write. AsyncGroup.Wait sees a nil error and the statement succeeds.
  • Table dump of a zero-byte object (pkg/frontend/table_dump.go streamTableDumpFile 691–712, recorded at 791–799) stores size 0 and the empty SHA-256, and adds the fixture path. Unlike the server-side copy branch, this path does not StatFile the destination.
  • Backup streamCopyFile (pkg/backup/tae.go 833–875) returns the empty hash and a nil error.
  • FileServiceWriter.Close (pkg/fileservice/file_service_writer.go 49–66, 86–96) returns nil after an empty pipe.

WriteMultipartParallel handles the same empty reader by calling Write with a non-nil size of 0 (aws_sdk_v2.go 640–642), which takes the small-object PutObject path. A known Size: 0 entry does the same. Only the nil-sizeHint empty stream reports success without creating the key.

Expected Behavior

An empty unknown-size write should leave a zero-byte object at the key and return nil, matching the parallel empty path and a Size: 0 PutObject. If the multipart upload is not completed, Write should return the error and the existing defer should abort the upload id.

Steps to Reproduce

  1. Build an AwsSDKv2 client against S3 or a mock that records CreateMultipartUpload, PutObject, CompleteMultipartUpload, and AbortMultipartUpload.
  2. Call Write(ctx, key, bytes.NewReader(nil), nil, nil).
  3. The call returns nil. HeadObject / GetObject is not found. ListMultipartUploads still contains the upload created in step 2. PutObject and CompleteMultipartUpload were not called.

The same outcome comes from S3FS created with ParallelMode: ParallelOff and Write of an IOVector whose only entry is {Size: -1, ReaderForWrite: bytes.NewReader(nil)}.

Additional information

A non-empty nil-sizeHint stream still uploads one part and completes, so a data-branch output that writes COMMIT;\n before close is not this case. The failure is the zero-byte stream. Each such statement leaks one incomplete multipart upload in addition to publishing a missing key.

Activity

  1. added
    kind/bug
    on Sep 22, 2026
  2. added theissue type on Sep 23, 2026
  3. added this to the MO-202609 milestone on Sep 23, 2026
  4. self-assigned this
    on Sep 23, 2026
  5. added a commit that references this issue on Sep 25, 2026
    7ce7834
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地源码定向 UT(Go 1.26.5,macOS arm64)
    • 测试日期:2026-09-27

    原问题验证

    该问题依赖内部 reader 生命周期或 I/O 故障注入,公开 SQL 无法稳定制造目标失败点。已在最新 main 上运行对应定向测试 TestAwsSDKv2WriteUnknownSizeEmptyCreatesObject 及 multipart abort/cancel 测试,连续 3 次通过。

    Happy Path 覆盖

    1. unknown-size 空 S3 stream 成功创建零字节对象。

    Unhappy Path 覆盖

    1. 覆盖分片失败 abort、读取前取消、abort 失败和 stalled body deadline,均受控返回。

    白盒验证

    确认修复提交 7ce783464806490263c184f22aaf5d307225adef 是当前 main 的祖先,并直接执行该提交新增的定向测试,结果 3/3 PASS。

    回归测试

    回归已落在 MatrixOne UT:TestAwsSDKv2WriteUnknownSizeEmptyCreatesObject 及 multipart abort/cancel 测试。未加入 MOTR,因为该场景必须注入内部 reader/I/O 失败,SQL 黑盒无法可靠触发;按覆盖矩阵应保留在 UT 层。

    测试证据

    • MatrixOne main commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 修复提交:7ce783464806490263c184f22aaf5d307225adef
    • 定向 Go 测试:3/3 PASS

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions