Repository navigation
[Storage] Rewrite Firebase.Storage in pure C# - #1555
AustinBenoit wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.
17ef195 to
96b0882
Compare
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.
a59e8ed to
ab9b113
Compare
❌ Integration test FAILEDRequested by @AustinBenoit on commit ab9b113
|
…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.
ab9b113 to
81aca7a
Compare
Description
Rewrites
Firebase.Storagein pure C# on top of the Firebase Storage REST API, removingFirebaseCppStorage, Androidfirebase-storage-unity, and iOSFirebaseStorage.Firebase.Storageas C# source underAssets/Firebase/FirebaseStoragewithFirebase.Storage.asmdef(matchingFirebase.FunctionsandFirebase.FirebaseAI), and removes the hard package dependency onFirebase.Auth(Auth and App Check tokens are attached viaFirebaseInteropswhen present).256 KB–32 MBchunks) populatingUploadState.UploadSessionUrion all platforms; automatic HTTPRange+ETagdownload resume; live forward-onlyGetStreamAsync().FileStreamI/O on background worker threads (StorageTaskScheduler), lazyFileStreamopen onPutFileAsync, and a connection-scopedStallWatchdogdisarmed while idle.StorageControllerpause/resume/cancel alongsideCancellationToken.Firebase.Storage.dllis replaced by source +Firebase.Storage.asmdef, SWIG*Internaltypes are removed, and behavior changes are listed below.libcurl/NSURLSession/ AndroidHttpURLConnection) to bypass Unity's ~10–12 MiB/sUnityTlsStreamdownload 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_transportinfirebase-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 infirebase-unity-sdk).Changelog
Firebase.Storage.dllis now shipped as C# source with an assembly definition of the same name (updateprecompiledReferencesin your own asmdefs accordingly), theFirebaseCppStoragenative libraries,firebase-storageAndroid dependency andFirebaseStorageiOS dependency are gone, and thecom.google.firebase.storageUPM package no longer depends oncom.google.firebase.auth(add it to your project if you relied on it being pulled in transitively).UploadState.UploadSessionUrion all platforms so interrupted uploads can be resumed via thepreviousSessionUriparameter ofPutBytesAsync,PutFileAsync, andPutStreamAsync.StorageController, which can be passed to the upload and download methods onStorageReferenceto pause, resume or cancel a transfer in progress.StorageReference.GetStreamAsync()now returns a live, forward-only network stream instead of a bufferedMemoryStream(CanSeekisfalse).StorageReference.Parentreturnsnullfor the root reference, as documented and as on other platforms, instead of another root reference.OperationCanceledException(the task is stillIsCanceled); code catching the derivedTaskCanceledExceptionshould catchOperationCanceledExceptioninstead.MetadataChangeproperty or custom metadata value tonullnow clears that field on the server instead of throwing.FirebaseStorage.GetInstancewithout a configured bucket no longer fails when creating references; operations on such references fail withStorageException.ErrorBucketNotFound.StorageReference.ListAsyncvalidates thatmaxResultsis between 1 and 1000.StorageException.HttpResultCodenow carries the real HTTP status returned by the server (previously a synthetic code), andInnerExceptionis populated for network failures.Testing
57tests inUIHandlerAutomated.cs) and opt-in network-chaos proxy suite (11scenarios inUIHandlerChaos.cs).2022.3.76f1Mono,6000.6.2f1Mono,6000.6.2f1IL2CPP, and CI (Playmode,Windows,macOS,Linux,AndroidFTL, plus iOS.ipabuild).Type of Change
Place an
xthe applicable box: