Files
seaweedfs/weed/s3api/s3err
cbce146a63 s3api: keep a long CopyObject/UploadPartCopy alive with whitespace, as AWS does (#12862)
* s3api: keep a long CopyObject/UploadPartCopy alive with whitespace, as AWS does

CopyObject and UploadPartCopy copy every chunk and only then write the
response. On a slow volume disk (~10 MB/s), or when the source is a
remote-only file of a remote-mounted bucket that is fetched first, a copy of
tens of MB sends no byte for 20-30 s. Clients with a low-speed check give up
while the copy finishes: the AWS SDK for C++ (pyarrow, among others) sets
libcurl's CURLOPT_LOW_SPEED_LIMIT to 1 byte/s over a few seconds, and the
abandoned copy leaves an orphan.

AWS S3's documented behaviour for long copies: answer 200 at once, keep the
connection alive with whitespace, then send <CopyObjectResult> (or an
<Error> document) in the body. This does the same:

- Once every check that refuses with its own status has run (auth, missing
  source, preconditions, invalid arguments, ACL and lock headers, the
  remote-cache 503), a copy still running after 1 s commits to 200,
  application/xml and the XML declaration, then sends one space a second,
  flushed, until <CopyObjectResult>/<CopyPartResult> (checksum in the body)
  or an <Error> with the code the handler would have answered. A copy that
  ends sooner answers byte for byte as before.
- Armed before a remote-only source is fetched into the cluster, which is
  the slow part on a remote-mounted bucket.
- Never kept alive: the metadata-only self-copy; a destination with
  versioning Enabled (x-amz-version-id is known only after the copy); a part
  copy whose upload or request carries SSE (its response headers are known
  only after the copy).
- One goroutine owns the ResponseWriter from arming until halt() returns;
  a client that leaves ends it without touching the copy.
- s3err gains StartStreamingResponse, ErrorResponseFor and EncodeXMLBody,
  shared with WriteErrorResponse.

Accepted: a slow failure is 200 + <Error>, as on AWS, and the request is
counted as 200.

Tests: s3api_object_handlers_copy_keepalive_test.go (slow success and
failure, fast unchanged, a refusal keeps its status, part copy, versioned
destination, SSE-C part, checksum in the body, remote fill covered, client
gone under -race, slow lookup then bad tag = 400, self-copy 412 under the
lock, part range on a remote-only source). With the keep-alive forced off,
the slow-copy tests fail.

* s3api: send a block of spaces per copy keep-alive tick

libcurl rounds its measured rate down, so one byte a second sits right
at the AWS SDK for C++'s 1 byte/s low-speed limit and jitter can trip it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3api: audit a kept-alive copy error at the 200 it was sent with

Once the keep-alive has sent 200, the <Error> rides in that response, so
the access log records 200 and the error code, as AWS server access logs do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3api: fill a conditional remote-only copy source before the keep-alive

A source condition read the filled entry only after the keep-alive had
committed 200, so a slow fill turned its 412 (or the 400 of a malformed
date) into an <Error> inside a 200. With any x-amz-copy-source-if-*
header the fill runs first, as it did before the keep-alive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3api: fill a remote-only self-copy that moves data under the keep-alive

Only a self-copy that can stay metadata-only needs its source filled
before the keep-alive; one that re-encrypts takes the data path, so its
fill is the slow part the keep-alive is for. A fill changes no
encryption state, so the unfilled entry decides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3api: test that the copy keep-alive reaches a client mid-copy

A ResponseRecorder keeps every write, flushed or not; over a real
connection the declaration and the spaces must arrive while the copy is
still held.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* s3api: bound the copy keep-alive streaming test with a request deadline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 13:05:04 -08:00
..