firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.57k stars 1.46k forks source link

Firebase Storage Upload/Download Failures #12812

Closed KunalxBhandari closed 3 months ago

KunalxBhandari commented 5 months ago

Description

I'm using firebase storage in order to upload some files and download those files later. I'm using the code down below in order to download the files from firebase storage.

func downloadFileFromFirebase(fireBasePath: String, localURL: String) { let fireBaseStorage = Storage.storage().reference() let storeRef = fireBaseStorage.child("(String(describing: fireBasePath))") let downloadTask = storeRef.write(toFile: localURL)

downloadTask.observe(.progress) { snapshot in // Updating the progress bar }

downloadTask.observe(.success) { snapshot in //Updating the UI } }

Here, what I noticed is that my downloadTask.observe closures are not invoking and I did some digging in the framework and found out that my task is never enqueued and the StorageDownloadTask is deallocated before that.

Screenshot 2024-04-18 at 2 28 45 PM

Line 110 is never executed.

Screenshot 2024-04-18 at 2 33 44 PM

Here in StorageReference on Line 204 we are creating a strong reference cycle with StorageDownloadTask but still it is deallocating before the enqueue implementation I don't know why. So, in order to confirm that issue is happening due to this deallocation reason, I deliberately created a retain cycle in StorageReference and made sure that the StorageDownloadTask is not deallocated.

Screenshot 2024-04-18 at 2 40 37 PM Screenshot 2024-04-18 at 2 41 23 PM

And after creating this retain cycle my downloadTask.observe closures are invoking and I'm able to download the media from firebase storage. But this is not a solution to the problem as it will create retain cycle. Can somebody help with this problem and tell me why this is happening?

This problem started coming after 10.2.0 versions. Currently, I'm using the 10.24.0 version.

Reproducing the issue

No response

Firebase SDK Version

10.24.0

Xcode Version

15.3

Installation Method

CocoaPods

Firebase Product(s)

Storage

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json Replace this line with the contents of your Package.resolved. ```

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
```yml Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 5 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

paulb777 commented 5 months ago

Sorry about the trouble @KunalxBhandari. I'm not able to reproduce. The only possible impacting change since 10.2.0 I see is https://github.com/firebase/firebase-ios-sdk/pull/10492 and I'm not sure why that would matter.

I'm not sure how the task could be deallocated between the StorageDownloadTask init and the task.enqueue() call.

Does adding a wait or sleep to the bottom of downloadFileFromFirebase make a difference?

Are you able to share a sample app that reproduces the issue?

KunalxBhandari commented 5 months ago

@paulb777 I'm using putData, delete, putFile, getMetadata, downloadURL functions of Storage and all of these are working fine expect the write function which I'm using for downloading the file from firebase storage. But on using sleep it's working fine. Is there any particular reason why this function is behaving like this?

paulb777 commented 5 months ago

It's possible the write to FirebaseStorage is succeeding, but the UI doesn't update because the function finishes first.

klinkert0728 commented 5 months ago

Hello, I'm facing a similar issue, where the downloadProgressBlock never gets called line 134 never gets executed.

Screenshot 2024-04-29 at 17 04 34

Any idea what could cause this ?

klinkert0728 commented 5 months ago

nor the fetcherCompletion Screenshot 2024-04-29 at 17 48 53

paulb777 commented 4 months ago

Does the app finish before the write completes?

google-oss-bot commented 4 months ago

Hey @KunalxBhandari. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

KunalxBhandari commented 4 months ago

I used the Thread.sleep(0.1) before my function body ends and now code is working fine. But like I explained, I was not getting the callback because the firebase object was deallocating. I don't know why that was happening but for now thread sleep seems to have worked for me.

klinkert0728 commented 3 months ago

is there any update here ?

paulb777 commented 3 months ago

I'm still not able to reproduce. When I add the code above into an app, I see the breakpoint in enqueueImplementation hit before the deallocation.

Would you share a fully reproducible example?

klinkert0728 commented 3 months ago

I would love to but unfortunately I can't.

google-oss-bot commented 3 months ago

Hey @KunalxBhandari. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 3 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@KunalxBhandari if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.