Skip to content

[Storage] Rewrite Firebase.Storage in pure C# - #1555

Open
AustinBenoit wants to merge 3 commits into
mainfrom
ab-pure-csharp-storage
Open

AustinBenoit wants to merge 3 commits into
mainfrom
ab-pure-csharp-storage

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Rewrites Firebase.Storage in pure C# on top of the Firebase Storage REST API, removing FirebaseCppStorage, Android firebase-storage-unity, and iOS FirebaseStorage.

  • Packaging & Dependencies: Ships Firebase.Storage as C# source under Assets/Firebase/FirebaseStorage with Firebase.Storage.asmdef (matching Firebase.Functions and Firebase.FirebaseAI), and removes the hard package dependency on Firebase.Auth (Auth and App Check tokens are attached via FirebaseInterops when present).
  • Resumable Transfers, I/O & Reliability:
    • Adaptive resumable uploads (256 KB–32 MB chunks) populating UploadState.UploadSessionUri on all platforms; automatic HTTP Range + ETag download resume; live forward-only GetStreamAsync().
    • 256 KB synchronous FileStream I/O on background worker threads (StorageTaskScheduler), lazy FileStream open on PutFileAsync, and a connection-scoped StallWatchdog disarmed while idle.
    • Adds StorageController pause/resume/cancel alongside CancellationToken.
  • Public API Compatibility: Preserves all existing public signatures (source-compatible with existing calls). Firebase.Storage.dll is replaced by source + Firebase.Storage.asmdef, SWIG *Internal types are removed, and behavior changes are listed below.
  • Note on Native HTTP Transport: The platform-native HTTP transport (libcurl / NSURLSession / Android HttpURLConnection) to bypass Unity's ~10–12 MiB/s UnityTlsStream download cap is split out into paired follow-up Draft PRs: [App] Add cross-platform streaming native HTTP transport (firebase_http_transport) firebase-cpp-sdk#1996 (firebase_http_transport in firebase-cpp-sdk) and [App][Storage][Functions][AI] Route pure-C# HTTP stack through C++ native firebase_http_transport #1579 (routing Storage, Functions, and Firebase AI Logic through it in firebase-unity-sdk).

Changelog

  • Storage: Rewrote the internal implementation in C#, removing the dependency on the C++ and native platform Storage libraries. Firebase.Storage.dll is now shipped as C# source with an assembly definition of the same name (update precompiledReferences in your own asmdefs accordingly), the FirebaseCppStorage native libraries, firebase-storage Android dependency and FirebaseStorage iOS dependency are gone, and the com.google.firebase.storage UPM package no longer depends on com.google.firebase.auth (add it to your project if you relied on it being pulled in transitively).
  • Storage: Populated UploadState.UploadSessionUri on all platforms so interrupted uploads can be resumed via the previousSessionUri parameter of PutBytesAsync, PutFileAsync, and PutStreamAsync.
  • Storage: Added StorageController, which can be passed to the upload and download methods on StorageReference to pause, resume or cancel a transfer in progress.
  • Storage: Behavior Change StorageReference.GetStreamAsync() now returns a live, forward-only network stream instead of a buffered MemoryStream (CanSeek is false).
  • Storage: Behavior Change StorageReference.Parent returns null for the root reference, as documented and as on other platforms, instead of another root reference.
  • Storage: Behavior Change Awaiting a canceled transfer throws OperationCanceledException (the task is still IsCanceled); code catching the derived TaskCanceledException should catch OperationCanceledException instead.
  • Storage: Behavior Change Setting a MetadataChange property or custom metadata value to null now clears that field on the server instead of throwing.
  • Storage: Behavior Change FirebaseStorage.GetInstance without a configured bucket no longer fails when creating references; operations on such references fail with StorageException.ErrorBucketNotFound. StorageReference.ListAsync validates that maxResults is between 1 and 1000.
  • Storage: StorageException.HttpResultCode now carries the real HTTP status returned by the server (previously a synthetic code), and InnerException is populated for network failures.

Testing

  • Expanded automated integration test suite (57 tests in UIHandlerAutomated.cs) and opt-in network-chaos proxy suite (11 scenarios in UIHandlerChaos.cs).
  • Verified across Unity 2022.3.76f1 Mono, 6000.6.2f1 Mono, 6000.6.2f1 IL2CPP, and CI (Playmode, Windows, macOS, Linux, Android FTL, plus iOS .ipa build).

Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request rewrites the internal implementation of the Firebase Storage Unity SDK in pure C#, completely removing the dependency on the C++ SDK and native platform Storage libraries. It introduces new C# classes to handle HTTP REST communication, resumable uploads/downloads, concurrency scheduling, and stall watchdogs. Additionally, it updates metadata, progress tracking, and exception handling to work natively in C#, and adds comprehensive integration tests. Feedback on the changes highlights a potential race condition in 'FirebaseStorage.cs' between 'Dispose()' and 'GetInstance()' when accessing the cached instances dictionary, and suggests synchronizing these operations with a lock.

Comment thread storage/src/FirebaseStorage.cs Resolved
Comment thread storage/src/FirebaseStorage.cs Resolved
@AustinBenoit AustinBenoit added the tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). label Oct 29, 2026
@AustinBenoit
AustinBenoit marked this pull request as draft November 4, 2026 18:06
@AustinBenoit
AustinBenoit force-pushed the ab-pure-csharp-storage branch 2 times, most recently from 17ef195 to 96b0882 Compare November 11, 2026 21:55
Rewrites Firebase.Storage on top of the Firebase Storage REST API,
removing the C++ SWIG bindings and native platform Storage libraries
(FirebaseCppStorage, Android firebase-storage-unity, and iOS
FirebaseStorage).

- Ships Firebase.Storage as C# source under Assets/Firebase/FirebaseStorage
  with Firebase.Storage.asmdef and removes the hard package dependency on
  Firebase.Auth (Auth and App Check tokens are attached via
  FirebaseInterops when present).
- Implements GCS resumable uploads with adaptive chunking (256 KB to
  32 MB) and UploadState.UploadSessionUri / previousSessionUri resumption,
  and HTTP Range downloads with ETag verification and a live forward-only
  stream from GetStreamAsync().
- Unifies retry, 60s stall detection, and pause/cancel handling in
  StorageTask.RunAttemptAsync and RetryBackoff bounded by
  MaxUploadRetryTime / MaxDownloadRetryTime / MaxOperationRetryTime, with
  StorageTaskScheduler concurrency limits (2 uploads / 3 downloads /
  5 commands).
- Adds StorageController and trailing optional controller parameters on
  upload and download methods to pause, resume, or cancel transfers.
- Adds automated integration tests in UIHandlerAutomated.cs covering
  session URI persistence and partial upload resumption, adaptive
  multi-chunk uploads, live stream downloads, root reference validation,
  metadata field clearing, concurrency throttling, mid-transfer token
  cancellation, and StorageController pause/resume/cancel flows.
- Adds opt-in network-chaos scenarios in UIHandlerChaos.cs (enabled via
  FIREBASE_STORAGE_CHAOS) exercising mid-transfer blackouts, TCP resets,
  throttling, latency/jitter, ETag replacement, and soak testing.
@AustinBenoit
AustinBenoit force-pushed the ab-pure-csharp-storage branch from a59e8ed to ab9b113 Compare November 24, 2026 13:48
@AustinBenoit AustinBenoit changed the title [Storage] Rewrite Firebase.Storage in pure C# [Storage] Rewrite Firebase.Storage in pure C# with native HTTP transport Nov 24, 2026
@github-actions github-actions Bot added the tests: failed This PR's integration tests failed. label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

❌  Integration test FAILED

Requested by @AustinBenoit on commit ab9b113
Last updated: Tue Nov 24 07:27 PST 2026
View integration test log & download artifacts

Failures Configs
[TEST] [ERROR] [2022] [1/2 Build OS(s): macos] [1/2 Platform(s): 26] [1/6 Test Device(s): iOS]

@AustinBenoit
AustinBenoit marked this pull request as ready for review November 24, 2026 15:40
…probing

- Uses 256 KB synchronous FileStream I/O on background worker threads (StorageTaskScheduler) and lazy FileStream opening in PutFileAsync.
- Makes StallWatchdog connection-scoped and disarms it while idle between GetStreamAsync consumer reads.
- Makes process thread-count probing in UIHandlerChaos.cs IL2CPP-safe.
@AustinBenoit
AustinBenoit force-pushed the ab-pure-csharp-storage branch from ab9b113 to 81aca7a Compare November 26, 2026 20:55
@AustinBenoit AustinBenoit changed the title [Storage] Rewrite Firebase.Storage in pure C# with native HTTP transport [Storage] Rewrite Firebase.Storage in pure C# Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests: failed This PR's integration tests failed. tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant