Skip to content

fix(storage): retry S3 internal errors and replayable transport failures - #13979

Merged
ChiragAgg5k merged 7 commits into
mainfrom
fix/storage-s3-retry-transient
Sep 29, 2026
Merged

ChiragAgg5k merged 7 commits into
mainfrom
fix/storage-s3-retry-transient

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

S3\RetryStrategy only retried throttling (SlowDown, 429/503) and never retried a transport failure. Backblaze B2 answers a failed part or completion with 500 <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.

Outcome Before After
InternalError (any status) not retried retried
500 / 502 / 504 without a parseable error code not retried retried
Parseable non-transient code (AccessDenied, NoSuchKey, …) not retried not retried
Retry-After: <seconds> ignored honoured, capped at maxDelay
Host did not resolve / connection refused (CURLE_COULDNT_CONNECT) not retried retried, any method
Connection dropped or timed out (incl. 60s stall watchdog), PUT/GET/HEAD/DELETE not retried retried
Connection dropped or timed out, POST not retried not retried
TLS / proxy / protocol failure not retried not retried

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 InternalError answer is safe, since finalize() 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-After honoured 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.
  • S3Test through 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.
  • Every new behaviour test fails against the previous strategy.
  • bin/monorepo test storage (128 unit, 32 e2e) and bin/monorepo check storage pass.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

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.
@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The open findings are fixed or were not real: copyObject() now handles a replayed completion, and Device::upload() finalizes on the last chunk, so the six-request assertion holds.

The PR widens S3 retries. It now retries InternalError responses, 5xx responses without a parseable error code, numeric Retry-After headers (capped at maxDelay), and some transport failures, while still refusing to replay ambiguous POSTs and conditional writes. The newest commits make large multipart server-side copies treat a replayed completion's NoSuchUpload as success when the target object exists, which matches how finalize() already handles it. They also add an integration test for that case.

Latest changes: A replayed multipart completion in copyObject() now counts as success when the target object exists, and a regression test covers large copies; a comment in the multipart upload test notes that the last chunk completes the upload.

Verdict New comments Fixed Still open
✅ Approved 0 2 0
📂 Walkthrough · 4
File Change
packages/storage/src/Device/S3/RetryStrategy.php Classifies rejected vs possibly-applied failures; retries InternalError, 5xx fallbacks, Retry-After, and replayable transport errors.
packages/storage/src/Device/S3.php copyObject() treats NotFound on multipart completion as success when the target exists, so it no longer aborts a copy that already landed.
packages/storage/tests/Device/S3/RetryStrategyTest.php Unit tests for the retry rules across status codes, error codes, methods, and transport errors.
packages/storage/tests/Device/S3Test.php Integration tests for multipart upload through internal errors, conditional writes, and a large copy whose completion is replayed.
✅ Fixed since the last review · 2
  • Finish the multipart upload before asserting six requests · packages/storage/tests/Device/S3Test.php:425
  • Handle replayed completions in large server-side copies · packages/storage/src/Device/S3/RetryStrategy.php:139

Reviewed the commits since 729c2b4 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes S3 retry logic for internal errors and transport failures.

The PR appears safe to merge; no new actionable issue or outstanding previous finding was identified.

Summary

The PR expands S3 retries for transient responses and replayable transport failures, while withholding ambiguous retries for multipart creation, batch deletion, and conditional writes. The latest change removes multipart-copy completion recovery and adds a regression test for an unproven completion.

Reviews (5) · Last reviewed commit: "fix(storage): report an unproven multipa..."

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.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/storage-s3-retry-transient (after).

Metric Before After Change
🚀 Requests/sec 189.62 202.22 🟢 +6.6%
⏱️ Latency P50 88 ms 86.02 ms ⚪ -2.2%
⏱️ Latency P95 213.39 ms 196.28 ms 🟢 -8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 86.02 196.28 12,540 202.22 -17.11
Account 162.81 291.48 660 11.33 -26.69
TablesDB 81.6 155.07 6,820 111.91 -6.58
Storage 83.59 180.95 3,300 56.09 -9.41
Functions 122.05 232.02 1,760 30.63 -25.51

Top API waits (after)

API request Max wait (ms)
account.prefs.update 457.09
account.name.update 425.21
functions.create 413.11
functions.variables.update 355.79
functions.delete 348.53

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

Comment thread packages/storage/src/Device/S3.php Resolved
…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.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread packages/storage/src/Device/S3.php Resolved
…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.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread packages/storage/src/Device/S3.php Resolved
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.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

@ChiragAgg5k
ChiragAgg5k merged commit 5c1bf95 into main Sep 29, 2026
59 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/storage-s3-retry-transient branch September 29, 2026 12:53
abnegate added a commit that referenced this pull request Sep 29, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants