DownloadManager - understanding ERROR_HTTP_DATA_ERROR
Asked Answered
S

3

17

My application depends heavily on android DownloadManager component to download files with approximate size of 3-10 mega bytes.

when scaling up (to millions of downloads) the big picture is clear:

~50% of all downloads are failing due to ERROR_HTTP_DATA_ERROR.

I'm getting this info from google analytics

according to the documentation, this error code stands for:

Value of COLUMN_REASON when an error receiving or processing data occurred at the HTTP level.

I found this documentation not very informative.
there are plenty of http errors out there.

and what about network disconnection in the middle of the download? does it also triggers the ERROR_HTTP_DATA_ERROR error after failing all the download's manager retry attempts?

It would be great if someone could help me to understand:

  • is there any way to get from DownloadManager more information about the exact http error?
  • what are the most common situations ERROR_HTTP_DATA_ERROR can be fired by download manager?

another point that worth mentioning: while this errors accruing - the user is connected to WIFI network (I'm setting download manager to download only over wifi)

please don't suggest me not to use download manager at all. I know about this option, advantages and disadvantages. I'm saving this option as a last resort.

Signore answered 14/1, 2016 at 6:26 Comment(5)
no, I don't. because as I'm getting this errors from other users via google analytic s.Signore
have you checked what's happening on the server side (if it's your own code running there)? Do you have any info as to which device types are experiencing the issue?Estimation
Can you share some more details like what server is used for downloading? Because it seems to me, something from server/network not mobile/client.Wirehaired
@SharpEdge: amazon CDN serverSignore
clear the cache of Download manager app , it helped meIda
W
11

Looking at the Source of DownloadManager ERROR_HTTP_DATA_ERROR is returned by a method getErrorCode(int) this is the exact line:

            case Downloads.Impl.STATUS_HTTP_DATA_ERROR:
            return ERROR_HTTP_DATA_ERROR;

android.provider.Downloads has statuses which are masked here with DownloadManager class's own constants, in its source:

public static final int STATUS_HTTP_DATA_ERROR = 495;

Now you got to find out what causes HTTP error 495. After Googling a bit I came to find out that this error response code is Google related only and is often produced when downloading apps from the playstore.

A fix suggested to Go to Settings - Apps- All- Download manager and Clear data.

So in conclusion of my limited research, I think its an underlying DownloadManager implementation related problem rather then some network or server problem, and since no definite solution/workaround is available (my friends also faced a similar situation) you should try other alternatives.

Wirehaired answered 25/1, 2016 at 11:6 Comment(3)
I can see in the source code (line 435) that this status code can be thrown when there is IOException : android.googlesource.com/platform/packages/providers/…Signore
@downvoter care to comment whats wrong with my answer ? Its not a complete solution but I put my efforts to it to at least get something.Wirehaired
clearing data solved the problem (after having configured the networkSecurityConfig as should be in android manifest)Creuse
Z
7

what are the most common situations ERROR_HTTP_DATA_ERROR can be fired by download manager?

Without seeing any code it's guess work. From the docs:

If an HTTP error occurred, this will hold the HTTP status code as defined in RFC 2616.

This will give you a standard http error from which you can find a 6.1.1 Status Code and Reason Phrase. If you are having millions of downloads, and these are from a limited array of sites, this could be a problem that is beyond your app, as the website's servers may not be coping with the traffic.

and what about network disconnection in the middle of the download?

Internet connectivity issues could cause;

"408"  ; Section 10.4.9: Request Time-out

does it also triggers the ERROR_HTTP_DATA_ERROR error after failing all the download's manager retry attempts?

Possibly. For it to throw this type of error, it needs to be a problem with the app communicating with and/or attempting to and/or finishing the download at the website.

is there any way to get from DownloadManager more information about the exact http error?

Beyond using try and catches and logging the errors in the relevant methods where your app uses the DownloadManager, and then testing and waiting for the logcat when you get this error, the other option would be to remote use a library or third party tool to get remote error logging and crash reports of your deployed app.

There are many third party services and libraries that offer this, I am using one of the reputable open source libraries as an example.

As for online error and crash logging, ACRA is open source and provides this feature. This used to use Google products to store reports freely, but as usage has increased, Google has withdrawn this support, however there are features offered by ACRA and other providers, or you can manage your own reporting, but this may incur cost.

Implementing this is within the app code is relatively straight forward, by creating a class that hooks into your app by extending the application class and launches with the application.

import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(
    formUri = "http://www.backendofyourchoice.com/reportpath"
)
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // The following line triggers the initialization of ACRA
        ACRA.init(this);
    }
}

You'll also need to set up the back end reporting, and there are details provided on how to do this, as the options become increased. More detail can be found here, BasicSetup.

This blog by The Cheese Factory gives a detailed view of set up and other options for online error reporting How to setup ACRA, an Android Application Crash Tracking system, on your own host Application Crash Reports on Android

This will mean an update to your app, but you're going to have to do this anyway from the sounds of it.

Zabaglione answered 21/1, 2016 at 13:19 Comment(0)
E
2

It's difficult to say exactly what is the reason for the error you are getting. The error code you are receiving is too general.

Things I would do in order to resolve the issue:

  1. Try to see if there is any correlation between server load or server activity and the number of download failures. This would help determine if the problem originates in the server. If it does - you may increase your resources on the server side or try to find a way to decrease the load on your servers to minimize the download related problems. Heavy server loads or a large number of concurrent downloads may cause problems like the one you are having (bottle-necks, timeouts, locked resources on the server side etc.).

  2. If you come to the conclusion that your problem in on the client side - I would consider replacing the Android Download Manager with another one or write your won code to download the file (s).

I'd have to say that Ms Yvette's offer to add more logging is important. I do it in all my apps. Once you post more information about the problem - we'll be able to pin-point the problem and resolve it more quickly.

Estimation answered 21/1, 2016 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.