Skip to content

fix(s3): reclaim the replaced object version when the deletes queue refuses it - #14766

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/s3-overwrite-leak
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/s3-overwrite-leak

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Overwriting an object through the S3 API (PutObject on an existing key, CompleteMultipartUpload) writes the new version under a fresh path, updates the file row, then enqueues DELETE_TYPE_FILES for the old path. A failed enqueue was swallowed and a false return was ignored, so the old object stayed in storage with nothing pointing at it.

Case Before After
Enqueue succeeds worker deletes old path same
Enqueue throws / returns false old path leaked silently deleted inline, Console::warning
Inline delete also fails — Console::error with the path, request still 200
Row write fails after the new object is written new object deleted, but getFileSize() ran outside the try whole row build inside the try
if ($previousPath !== '' && $previousPath !== $path) {
    $this->reclaim($project, $publisherForDeletes, $deviceForFiles, $previousPath);
}

The queue stays the first choice: a backend delete can wait on an active GET of the same object, and the replacement is already live.

Test: S3CustomServerTest::testOverwriteWithoutDeletesQueue puts a string at the deletes queue key (every push fails with WRONGTYPE), overwrites by PUT and by multipart, and asserts the bucket holds one object. It breaks a queue for the whole stack, so it is in the queueRetry lane, which now also runs for Storage changes.

Related: appwrite-labs/cloud#6628

…he deletes queue is down

PutObject and CompleteMultipartUpload on an existing key write the new
version under a fresh path and hand the old one to the deletes queue. A
refused or failed enqueue is swallowed, so the old object stays in storage
with no file row pointing at it. The test breaks the deletes queue and
asserts the bucket holds exactly one object after each overwrite.

Runs in the queue lane, which now also triggers on Storage changes.
@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

…efuses it

An overwrite publishes the new version first and hands the old path to the
deletes worker, because a backend delete can wait on an active GET of the
same object. When the enqueue threw or returned false the old object was
left in storage with no row pointing at it. Delete it inline in that case
and log loudly only if storage refuses too; the request still succeeds,
since the replacement is already live.

The row build in PutObject now sits inside the try, so a failing size
lookup no longer orphans the new object, and cleanup errors no longer
mask the original failure.
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/s3-overwrite-leak (after).

Metric Before After Change
🚀 Requests/sec 216.85 223.77 ⚪ +3.2%
⏱️ Latency P50 79.51 ms 78.71 ms ⚪ -1%
⏱️ Latency P95 184.97 ms 175.51 ms 🟢 -5.1%
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 78.71 175.51 13,680 223.77 -9.46
Account 144.05 254.04 720 12.48 -7.33
TablesDB 76.99 142.69 7,440 124.3 -0.85
Storage 70.83 165.05 3,600 61.85 -8.62
Functions 107.02 202.97 1,920 33.76 -10.84

Top API waits (after)

API request Max wait (ms)
account.name.update 485.61
functions.create 427.14
account.prefs.update 350.18
tablesdb.rows.create 330.6
storage.buckets.create 316.91

@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review October 22, 2026 09:57
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The PR hardens putObject and completeMultipartUpload in the S3 module so a replaced object version is reclaimed via the deletes queue when possible and deleted inline when the queue is unavailable, with cleanup failures logged instead of masking the original request outcome. A new e2e test breaks the deletes queue with a Redis WRONGTYPE string and asserts both overwrite paths still clean up storage. The Storage service is added to an existing CI e2e lane.

Files Change
src/Appwrite/Platform/Modules/S3/Http/S3/Base.php Adds reclaim() (queue-first with inline fallback) and discard() (best-effort delete with logging) helpers and rewires both overwrite paths to use them.
tests/e2e/Services/Storage/S3CustomServerTest.php Adds testOverwriteWithoutDeletesQueue, which sabotages the deletes queue and asserts inline cleanup of replaced versions.
.github/ci/e2e.json Adds the Storage service to an existing e2e lane so the new test runs in CI.

Reviewed commit: bf5d757

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

S3 object replacement now falls back to deleting the prior immutable storage path inline when the deletes queue refuses publication, and logs cleanup failures without changing the completed request. The PUT file-size lookup is also inside the row-write cleanup boundary, and an end-to-end queue-outage test covers PUT and multipart overwrites in the queue-retry lane.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
.github/ci/e2e.json Adds Storage to the queue-retry end-to-end lane.
src/Appwrite/Platform/Modules/S3/Http/S3/Base.php Adds inline reclamation and best-effort cleanup logging for failed object-version queueing.
tests/e2e/Services/Storage/S3CustomServerTest.php Tests PUT and multipart replacement while the deletes queue refuses messages.

Reviewed bf5d757 · 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 S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit a704b1b into main Oct 22, 2026
71 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(s3): reclaim the replaced object version when the deletes queue refuses it

(cherry picked from commit a704b1b)
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.

1 participant