Repository navigation
fix(storage): retry S3 internal errors and replayable transport failures - #13979
Conversation
Backblaze B2 answers failed parts and completions with 500 InternalError ("internal incident"), which the strategy treated as permanent, so one flaky request failed a multi-hour backup. Retry InternalError and unparseable 500/502/504, honour Retry-After, and retry transport failures that cannot apply a request twice: anything that never reached the service, and dropped or timed-out non-POST requests.
🟢 Tier S · Ready to merge
The PR widens S3 retries. It now retries Latest changes: A replayed multipart completion in
📂 Walkthrough · 4
✅ Fixed since the last review · 2
Reviewed the commits since |
|
A CreateMultipartUpload or conditional PUT answered with InternalError, or dropped mid-flight, may already have been applied: replaying the first can orphan an upload, the second reports a false precondition failure. Retry those only when the request was rejected (throttled or never sent). Also recognise Swoole's refused connection.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Completions are now retried after a timeout, so a copy whose first completion landed can get NoSuchUpload on the replay. Treat it as success when the target exists, as finalize() already does, instead of aborting and reporting failure.
…eletes An existing target made NoSuchUpload look like a landed copy, so move() could delete its source for a copy that never completed; accept it only when the target's ETag is the multipart ETag of these parts. Batch deletes (POST ?delete) were replayable after an ambiguous outcome and could remove an object written in between; CompleteMultipartUpload is now the only POST replayed.
|
@greptile review |
…its ETag format The multipart ETag formula is AWS's and other S3-compatible providers may not follow it, which turned a landed copy back into a reported failure. Record the target's ETag before the copy and accept NoSuchUpload on the completion only when the target has since changed to an object of the source's size.
|
@greptile review |
Nothing distinguishes a copy whose replayed completion finds the upload gone from one that was aborted or overwritten; every inference tried could report a false success, letting move() delete a source that was never copied. Keep copyObject() as on main: repeating a copy is safe, a false success is not.
|
@greptile review |
#11649 conflicted with main again after main took 14 more commits (to d3cd0db): #13982's createdAt window pushdown for execution listings and #13979's S3 retry fixes in packages/storage. Main absorbed no further packages, and composer.json and composer.lock merge unchanged. Only src/Appwrite/Execution/Store.php conflicted: main added the createdAt window to latestWhere() beside the equality filter the train had moved to the query library's Method enum. The resolution keeps main's window logic with the train's QueryMethod::Equal, and main's new WINDOW_METHODS list names the same five methods as Method cases, since database 8 has no Query::TYPE_* constants and getMethod() returns the enum. filterSql() already renders those cases, and main's new StoreTest cases pass against the merged file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
S3\RetryStrategyonly retried throttling (SlowDown, 429/503) and never retried a transport failure. Backblaze B2 answers a failed part or completion with500 <Code>InternalError</Code><Message>internal incident</Message>, which the strategy treated as permanent. Cloud backups saw this 42 times in 7 days across 5 regions, and each one failed a multi-hour backup at the upload step.InternalError(any status)AccessDenied,NoSuchKey, …)Retry-After: <seconds>maxDelayCURLE_COULDNT_CONNECT)Why POST is excluded only for ambiguous transport failures: S3 writes with PUT to a fixed key or part number, so a replayed PUT overwrites itself. A POST that may already have landed could open a second multipart upload. A CompleteMultipartUpload that is retried after an
InternalErroranswer is safe, sincefinalize()already treats "upload gone, object present" as success.Budget is unchanged (3 retries, full-jitter backoff from 0.5s, ≤ ~3.5s before any
Retry-After), because the same client serves user-facing file requests. Riding out longer outages is left to callers (cloud's backup upload will retry the upload as a whole).Test Plan
RetryStrategyTest: InternalError retried; 429/500/502/503/504 fallback retried, 501 not; non-transient code on 503 not retried;Retry-Afterhonoured and capped, HTTP-date falls back to backoff; refused connection and DNS failure retried for POST; dropped/timed-out PUT retried, POST not; TLS not retried; transport retries capped.S3Testthrough the device with a scripted client: a multipart upload where one part and the completion each get B2's "internal incident" succeeds, re-sending the part body and completing with both ETags; a timed-out PUT is replayed with its body; a timed-out CreateMultipartUpload is not replayed.bin/monorepo test storage(128 unit, 32 e2e) andbin/monorepo check storagepass.Related PRs and Issues
Checklist