Skip to content

fix(fileservice): publish empty unknown-size S3 writes - #29344

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29266-aws-empty-stream
Sep 25, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29266-aws-empty-stream

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #29266

What this PR does / why we need it:

An empty unknown-size S3 write could return success after starting a multipart upload without creating an object or aborting that upload. Read the first sequential chunk before starting multipart; route an empty stream through the existing zero-byte PUT path. Nonempty writes keep their multipart sequence, and failures now reach the named return error so the upload is aborted. An already-canceled request is rejected before reading a potentially blocking source.

Both sequential and parallel multipart cleanup must survive caller cancellation, but the detached abort previously had no deadline. A stalled S3 error response body could hold Write indefinitely. Both paths now share one abort helper that retains context values, detaches caller cancellation, and applies a 30-second cleanup deadline. The original write error and any abort error remain discoverable. The success path adds no timer or request. The deadline bounds client cleanup effort; it cannot guarantee remote reclamation when the abort itself fails.

Validation after rebase onto main at e914d98764 (head 1610da4afb):

  • The original missing-object behavior was reproduced against main; the stalled-abort response-body hang was reproduced on the earlier PR head.
  • pkg/fileservice tests passed in CI's -short mode with -count=1 (194.287s). This package contains no testing.Short() skip branch.
  • The formerly flaky TestAWSMultipartAbortContextAndErrors now injects cancellation at the UploadPart HTTP transport boundary. It passed -race -count=100 on this head; the prior version failed 18 of 100 iterations. It retains assertions for the original cancellation error, exactly one abort, joined abort failure, and detached context values/deadline.
  • The unchanged stalled-body deadline test passed -race -count=30 on the prior head; its helper and production behavior are unchanged after rebase. AWS and S3FS tests cover empty object visibility, nonempty completion, read/PUT failure, and part-failure abort.
  • go vet ./pkg/fileservice and scoped golangci-lint v2.6.2 --new-from-rev e914d98764 ./pkg/fileservice passed (0 issues). Independent final review found no blockers.
  • A separate unshortened local package run hit its 4-minute whole-suite timeout during a disk-backed TestS3FS fsync. It is not counted as a pass; the CI-mode owning-package run above completed successfully.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 finding at pkg/fileservice/aws_sdk_v2.go:465: detached multipart abort has no cleanup deadline. context.WithoutCancel removes both cancellation and the caller deadline, while the configured HTTP client has Timeout=0 and ResponseHeaderTimeout only bounds receipt of response headers. If a failed upload is canceled and S3 returns an abort error response whose body stalls after headers, the SDK copies that body to EOF and Write cannot return; it retains the caller and upload resources indefinitely. Bound detached cleanup with a dedicated timeout and cover cancellation plus a stalled abort response. The empty-object publication path itself looks correct. Exact-head CI run 35988027326 is green, but it does not prove this cancellation/liveness path. COMMENT only because this is self-authored.

@XuPeng-SH
XuPeng-SH force-pushed the codex/issue-29266-aws-empty-stream branch from ce7487f to 8c58c4d Compare September 24, 2026 15:31

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of c42c34b37d9237d7f7a486ec5089c206745a8ebf against base/merge-base 36c3fbce2c99410d83bd084d1eb9f09044284012. All four changed files and their ownership/consumer paths were checked. No blocking findings; recommend merging. This is a COMMENT review because the authenticated account is the PR author; a code-owner approval is already present.

Closure Result
Empty unknown-size publication Write reads the first bounded chunk before acquiring an upload ID. An empty stream takes the existing zero-byte PutObject path, preserving Expires; success now means the key is visible. The S3FS regression checks StatFile, size zero, and duplicate-write rejection. A failed PUT does not report success. The original missing-object/leaked-upload path in #29266 is closed.
Q1: multipart ownership and error propagation Initial read/Create failures own no upload. Once Create succeeds, one defer aborts on UploadPart, later read, or Complete failure. Sequential error returns now reach the named result; parallel workers join before abort. Original write and abort errors remain discoverable via errors.Join. Abort failure is reported and may leave remote cleanup debt, which the PR accurately documents.
Q2: cancellation and termination Both multipart paths use one bounded abort helper. It keeps context values, detaches caller cancellation, and applies a 30-second deadline that covers response-body reads. The earlier unbounded-abort finding is closed. Already-canceled unknown-size requests are rejected before reading the source. The previously flaky cancellation test now injects a single terminal result at the UploadPart transport boundary; the prior review's 18/100 race failure is closed.
Q3: memory and performance Nonempty sequential writes keep the 64 MiB per-chunk read bound and existing multipart request count; the first read moves ahead of Create. No extra successful-write HTTP request, timer, goroutine, cache, or retry layer is added. Empty writes replace a dangling multipart Create with one zero-byte PUT. This does not claim a measured throughput change.
Engineering and scope The shared abort helper serves exactly the two existing paths; there is no new framework. The proxy change only defers test-context cancellation on early assertion failure. No new wire/catalog format, auth, or platform contract is introduced. This focused bug fix does not trigger a feature-design gate.

Evidence: git range-diff shows the three fileservice commits are patch-identical to the previously reviewed 1610da4afb series; the only additional PR commit changes the proxy test. main gained no pkg/fileservice changes between the old and new bases. The previously reviewed deterministic cancellation test passed -race -count=100, and the stalled-abort body test passed -race -count=30; the relevant code and fixtures are unchanged. Current-head CI run 36080904118 completed successfully, including UT, ARM64 SCA, coverage, and enabled multi-CN BVT. The review worktree is clean and git diff --check passes. No redundant local package rerun was needed. The PR body correctly excludes the earlier unshortened package timeout from pass evidence and records the successful CI-mode owning-package run.

@XuPeng-SH
XuPeng-SH merged commit 7ce7834 into matrixorigin:main Sep 25, 2026
17 of 19 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-29266-aws-empty-stream branch September 25, 2026 02:40
XuPeng-SH added a commit that referenced this pull request Oct 21, 2026
## What type of PR is this?

- [x] BUG
- [x] Improvement

## Which issue(s) this PR fixes:

Fixes #30737

## What this PR does / why we need it:

Cancelling asynchronous CSV/JSON conversion can leave a missing batch
result and make export finalization spin indefinitely. Finalization now
waits on ordered results or cancellation, releases completed entries,
and rejects incomplete closed streams.

ExportConfig owns cancellation and joining of conversion workers, file
pipes, the sink, and the per-file cancellation callback. Cleanup
preserves the primary error's concrete identity and keeps request
metadata alive until all users exit. Ordinary OUTFILE, DATA BRANCH CSV,
and stored-result dumping use this cleanup boundary. DATA BRANCH
coordination runs outside the converter pool and observes producer
cancellation once while draining results.

Stored-result dumping creates its own cancellation context and passes it
to the sink. A known header/source error therefore cancels a
context-cooperative sink before joining, even if it is waiting on
existence checks or admission rather than consuming the pipe. Dump
remains synchronous and allocates no unused conversion queue. The parent
request, borrowed shared service, process, and saved metadata retain
their ownership.

Rebased onto the target branch and aligned all `ExportConfig` method
receiver names, resolving CI staticcheck ST1016 without changing cleanup
behavior or suppressing diagnostics.

The 4.2-dev PR also backports #29344 for #29266: unknown-size empty S3
writes publish zero-byte objects, and failed multipart writes reach
bounded Abort cleanup. Sequential/parallel Abort retains context values,
survives caller cancellation, and has a 30-second deadline. Successful
Abort preserves primary error identity. SDK dependencies, nonempty chunk
sizing and successful request sequence remain unchanged.

## Validation

- Final frontend owning-package normal and full `-race -count=1` suites:
**1599 root tests passed in each**, with one existing skip.
- Rebase preserved all three functional commits. Backend source and
dependencies are unchanged; prior backend evidence remains applicable.
- New actual `doDumpQueryResult` regression covers oversized headers, a
source-file read failure after sink startup, parent cancellation,
primary error identity, joined sink, and continued
shared-service/metadata usability. Retained evidence from the identical
regression source records **100 race repetitions per branch**; all three
scenarios also passed in the post-rebase full race suites. A pre-repair
production-function overlay makes the source-error cell fail as expected
until independent parent cancellation; the probe cancels and drains
itself.
- Existing public SQL lifecycle test passed under race: exact CSV
contents, destination failure and same-session reuse. Existing
multi-block stored-result dump content test passed.
- Scoped `go vet`, configured `molint`, formatting, license-eye and
incremental configured `golangci-lint` passed. Full affected-package
lint reports 41 diagnostics: a separate clean `b7d2cc7b56` worktree
produces the identical complete diagnostic set after normalizing line
offsets. No new findings, no ST1016, no suppression. License-eye checked
all changed files (7 main / 11 release), 0 invalid; policy unchanged.
- Separate `gpt-6.1-sol` / `xhigh` design and final complete-PR review
passed with no unresolved material blocker. Local results are distinct
from remote CI.
- Retained backend evidence remains applicable: fileservice
owning-package suite (299 roots), affected AWS/S3 race tests (51 roots),
controlled HTTP Abort deadlines/errors, real SQL empty-object
publication, and combined SQL cancellation/prepared reuse. The later
unmodified-binary blackbox comparison reproduced the 4.2 baseline hang,
while this PR's export lifecycle passed 32/32 timed cancellations with
same-session health and correct normal CSV contents. No backend source
or dependencies changed in this follow-up.

Local validation artifacts:
`/home/xupeng/.codex/issue-to-pr/matrixone/30737/rebase-review/`
(`scope.json`, `results.json`, `run-validation.sh`, `*-normal.jsonl`,
`*-race.jsonl`, `*-public.jsonl`, `*-vet.log`, `*-molint.log`,
`*-lint.log`, `*-license.log`, exit receipts). The release baseline
comparison is `42-lint-comparison.json`; retained stress/negative
controls are in the adjacent `review-ci-repair/` directory.

## Performance and limits

Retains asynchronous conversion. Blocking finalizer waits replace busy
spinning. Stored-result dumping adds one child context; it adds no
conversion queue, worker or success-path backend request. No broad
throughput or long-soak guarantee is claimed.

Global admission bounds and arbitrary I/O that ignores cancellation
remain outside this fix. The separately tracked borrowed-service SQL
DATA BRANCH DIFF issue #30755 is unchanged.
Failed S3 writes can wait for the bounded Abort operation; the 30-second
cleanup budget does not bound the entire SQL request or arbitrary source
readers. Remote reclamation requires a successful Abort. The pre-upload
parallel cancellation schedule addressed by main #29312 remains a
separate known gap.

Remote CI is pending for the updated revision.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants