Skip to content

Stream native file downloads consistently during overwrites - #14615

Merged
loks0n merged 2 commits into
mainfrom
codex/native-storage-stream
Oct 17, 2026
Merged

loks0n merged 2 commits into
mainfrom
codex/native-storage-stream

Conversation

@loks0n

@loks0n loks0n commented Oct 17, 2026

Copy link
Copy Markdown
Member

Large native /view and /download responses reopen the backend object for every 10 MiB chunk. That adds a buffered backend read per chunk and can truncate a response when an S3 overwrite commits a new path and deletes the old one during delivery.

Use the existing storage device streaming interface for large, untransformed responses. One backend GET pins the representation for the transfer. Validate the captured length and abort the HTTP response if delivery fails after bytes have escaped, rather than appending an error document to a successful response. Small, encrypted, compressed, and range response paths retain their existing behavior.

Validation:

  • A London Linux drill against NYC production reproduced the old bug on both native endpoints: a 100 MiB read returned about 30 MiB plus error JSON after a concurrent S3 overwrite. The isolated candidate returned the complete original SHA-256 on both endpoints, with the next read returning the replacement. The overwrite completed after the client had consumed only 1,378 bytes.
  • Same-client, same-object, same-TCP-connection Fastly staging A/B, with both variants using the NYC shield: 12 hash-verified reads each; median throughput 44.74 → 49.67 MB/s, first byte 392 → 193 ms. No caching. Full upstream benchmark reruns are in progress; these are one-client diagnostics, not six-location aggregates.
  • Added an HTTP E2E regression for both native endpoints during an S3 overwrite, under the existing s3 group so it also exercises the MinIO-backed storage lane. This E2E has not yet been run locally; CI verification is required.
  • Targeted Pint and PHPStan pass; package wiring validation passes. The manual drill was seen fail on the deployed implementation and pass on the candidate.

The candidate is isolated to GET requests for two temporary benchmark buckets behind an explicit diagnostic header. General production traffic is unchanged. Deployment must wait for required review and CI; no admin bypass.

Refs appwrite-labs/cloud#6624

@loks0n loks0n self-assigned this Oct 17, 2026
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found.


The change reworks both file-serving endpoints to stream via one backend read instead of repeatedly reading fixed-size windows, tracking streamed bytes against the recorded sizeOriginal and aborting the response when the account diverges. A new testNativeReadDuringOverwrite e2e test exercises a 100MB download while a concurrent overwrite PUT replaces the object, for both view and download endpoints, against the S3 custom server.

Files Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php Switched to single-shot stream() with byte accounting and mid-stream abort() on size mismatch.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php Same streaming rework as Download for the view endpoint.
tests/e2e/Services/Storage/S3CustomServerTest.php Added an overwrite-during-download race test using a 100MB multipart upload and concurrent PUT.

Reviewed commit: cebe2f9

@ghost

ghost commented Oct 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes support the large-file E2E regression without introducing a concrete defect.

Large native /view and /download responses now use the storage device's streaming interface, validate the delivered length, and abort if delivery fails after response bytes have escaped. The S3 E2E suite exercises both endpoints during an overwrite, and CI configures a 128 MiB storage limit so the 100 MiB regression can run.

Latest changes: The newest commits set _APP_STORAGE_LIMIT to 128 MiB in the E2E jobs and remove the redundant explicit bucket size in the S3 helper, adding the bucket response as assertion diagnostics.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
.github/workflows/ci.yml Raises the storage limit in service and grouped E2E jobs to allow the 100 MiB regression.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php Streams large untransformed downloads and validates completion.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php Streams large untransformed views and validates completion.
tests/e2e/Services/Storage/S3CustomServerTest.php Adds overwrite-during-read coverage for both native endpoints and improves bucket setup failure diagnostics.

Reviewed the commits since cebe2f9 · 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

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

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/native-storage-stream (after).

Metric Before After Change
🚀 Requests/sec 166.57 175.68 🟢 +5.5%
⏱️ Latency P50 104.37 ms 99.18 ms ⚪ -5%
⏱️ Latency P95 239.85 ms 229.93 ms ⚪ -4.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 99.18 229.93 11,343 175.68 -9.93
Account 188.32 362.65 597 9.97 +23.69
TablesDB 95.95 181.83 6,169 98.9 -9.57
Storage 90.52 207.16 2,985 49.38 -12.19
Functions 138.44 273.4 1,592 26.94 -3.69

Top API waits (after)

API request Max wait (ms)
account.name.update 549.53
functions.variables.update 528.14
account.prefs.update 499.09
functions.create 469.31
functions.variables.delete 427.73

@loks0n
loks0n merged commit 9650df8 into main Oct 17, 2026
113 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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