3

I am using the Firebase iOS SDK and I am downloading images to memory with the "dataWithMaxSize" method. Downloading works well when the network connectivity is good, but if there is no network connectivity, then the download task will continue indefinitely without calling the error callback. It looks like the same problem was spotted in this SO post where the Firebase Android SDK is being used. If someone could provide some assistance with this issue I would greatly appreciate it.

Thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Wouter
  • 291
  • 4
  • 12

3 Answers3

2

I have done many tests setting maxUploadRetryTime with variety of TimeInterval (30, 20, 10, 8, 5, 2, 1) and I can confirm that setting maxUploadRetryTime = 1.0 would ONLY trigger the timeout failure block.

Some logs:

2017-05-03 21:15:17.922 [Info] [main] [UploadRequest.swift:40] upload(uploadData:) > Start uploading with Timeout: 1.0

2017-05-03 21:15:18.170 [Verbose] [main] [UploadRequest.swift:60] upload(uploadData:) > Upload failed

This is a very unexpected behaviour and I am not sure if they are aware of it. At the moment I am using Firebase/Database (3.17.0)

UPDATE:

I filed a bug to firebase team and they have confirmed the issue. Report number: 8-2338000016926

danialmoghaddam
  • 343
  • 1
  • 6
  • 21
0

you can check for Network availability before trying to download/upload any image,etc

like in android

 private boolean isNetworkAvailable() {

    getActivity().runOnUiThread(new Runnable() {
        public void run() {
            // Update UI here when network is available.

            ConnectivityManager connectivityManager
                    = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
            activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (!(activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting())) {

                Snackbar snackbar = Snackbar
                        .make(coordinatorLayout, "No internet connection!", Snackbar.LENGTH_INDEFINITE)
                        .setAction("RETRY", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                isNetworkAvailable();
                            }
                        });
                View sbView = snackbar.getView();
                snackbar.setActionTextColor(Color.WHITE);
                sbView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.snackbar_back_color2));
                TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
                //textView.setTextColor(Color.YELLOW);
                snackbar.show();

            }
        }
    });

    return (activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting());
}
Sahaj Rana
  • 1,993
  • 4
  • 25
  • 42
0

maxUploadRetryTime/maxDownloadRetryTime/maxOperationRetryTime are all properties on FIRStorage and you can set those to fail an operation the same way as described on the other post about android.

The way these timeouts work is that they are based on how long retries will be attempted. So if the setting is "4 seconds" and the connection stalls for 5 seconds, the operation will fail. If the operation continues without network interruption for 5 minutes, the operation will succeed (and you will get progress notifications periodically as data is transferred).

Benjamin Wulfe
  • 1,705
  • 13
  • 9
  • Note that the default timeout for uploads and downloads for both platforms is a relatively long 10 minutes. So it might seem that the operation is going to retry forever, but it does give up eventually. – Benjamin Wulfe Jun 14 '16 at 03:32
  • Thanks for you response. I am trying this option at the moment. The documentation on the website seems to be inaccurate: "Maximum time in seconds to retry a download, defaults to 60s." – Wouter Jun 14 '16 at 11:51
  • Unfortunately I'm not having any luck. I am setting the maxDownloadRetryTime like this: FIRStorage.storage().maxDownloadRetryTime = 5 The error callback is not being called even with a very short retry time of 5 seconds. I am using Network Link Conditioner with 100% packet loss to test the connectivity on Mac OS. I have noticed that the following error appears in the console: "Domain=NSURLErrorDomain Code=-1001 "The request timed out."" Do I need to attach one of the other observers to see the error? – Wouter Jun 14 '16 at 12:21
  • 1
    I've been debugging the file downloads by observing events for "Failure", "Pause", "Progress", "Resume" and "Success". I've set the maxDownloadRetryTime to 5 seconds and I've used the the Network Link Conditioner with 100% packet loss. When logging the output, I noticed that a "Progress" event is logged first followed by a "Resume" event. No other events occur after that. I've waited for a good few minutes with no change. I don't know if this is the intended behaviour, but it's very difficult to give the user feedback on a download in this type of scenario. There must be some other way. – Wouter Jun 14 '16 at 17:17