Skip to content

feat: support concurrent chunk uploads#95

Merged
TorstenDittmann merged 2 commits into
mainfrom
concurrent-chunk-uploads-1-9-x-minimal
May 21, 2026
Merged

feat: support concurrent chunk uploads#95
TorstenDittmann merged 2 commits into
mainfrom
concurrent-chunk-uploads-1-9-x-minimal

Conversation

@TorstenDittmann

Copy link
Copy Markdown
Contributor

This PR updates the SDK to support concurrent chunk uploads.

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors chunked file uploads to run up to 8 chunks concurrently using Interlocked counters and a resultLock for safe result aggregation. It also fixes a pre-existing threading bug where per-request headers were being written to the shared _http.DefaultRequestHeaders instead of the per-request request.Headers.

  • Concurrent workers: Chunks are dispatched via Interlocked.Increment over a pre-built list; the first chunk is uploaded sequentially to establish the upload ID before parallel workers start, avoiding any race on uploadId.
  • Header isolation fix: Moving header mutations from _http.DefaultRequestHeaders to request.Headers is a correct and important fix that prevents cross-request header pollution in concurrent call scenarios.
  • File handle leak resolved: The previous info.OpenRead() assignment that left a dangling FileStream in input.Data has been removed; ReadChunkAsync now opens a fresh, properly-disposed stream per chunk for the \"path\" source type.

Confidence Score: 5/5

Safe to merge; the concurrency logic is well-structured and the header-isolation fix removes a latent cross-request mutation bug.

The first chunk is uploaded sequentially before workers start, so uploadId is written exactly once before any parallel reads. Worker coordination via Interlocked and resultLock is correct. The only concern is a synchronous lock for stream reads that blocks thread pool threads, but this is a design-quality issue rather than a correctness defect.

Appwrite/Client.cs — the stream-read locking pattern in ReadChunkAsync is worth revisiting for thread-pool-constrained hosts.

Important Files Changed

Filename Overview
Appwrite/Client.cs Adds concurrent chunk uploads with up to 8 parallel workers using Interlocked/lock primitives; also fixes a critical threading bug where per-request headers were being mutated on the shared _http.DefaultRequestHeaders. Stream-backed inputs serialize reads via a synchronous lock inside the async method, which can block thread pool threads.

Reviews (2): Last reviewed commit: "feat: support concurrent chunk uploads" | Re-trigger Greptile

Comment thread Appwrite/Client.cs Outdated
@TorstenDittmann TorstenDittmann merged commit 7f1a2e1 into main May 21, 2026
1 check passed
@TorstenDittmann TorstenDittmann deleted the concurrent-chunk-uploads-1-9-x-minimal branch May 21, 2026 17:53
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