google / volley

https://google.github.io/volley
Apache License 2.0
3.37k stars 751 forks source link

Volley: [5311] NetworkUtility.logSlowRequests: HTTP response for request=<[ ] #443

Closed PanneerJan2 closed 1 year ago

PanneerJan2 commented 1 year ago

I Tried Many APIs and I'm getting NetworkUtility.logSlowRequests Warning and sometimes API Fails. I have Tried Increasing TimeOut Seconds and Increased Max Retries and Still i'm getting this warning Val queue = Volley.newRequestQueue(applicationContext)

val socketTimeOut = 30000 val jsonObjectRequest = JsonObjectRequest(Request.Method.POST,url,jsonObject,{res->

    },{error->

    })
    val policy: RetryPolicy = DefaultRetryPolicy(
        socketTimeOut ,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
    )
    jsonObjectRequest.setRetryPolicy(policy)
    queue.add(jsonObjectRequest)

Warning ->

Volley: [3288] NetworkUtility.logSlowRequests: HTTP response for request=<[ ] https://www.google.com 0xd61ac103 NORMAL 1> [lifetime=6260], [size=159369], [rc=200], [retryCount=1]

jpd236 commented 1 year ago

Sorry you're having trouble!

Volley is more or less just a thin wrapper around the classes which perform the actual HTTP request. Since you're using the default HTTP stack, that would be HttpURLConnection (unless you're running on a Froyo device or older for some reason), which is built into the Android platform.

I'd recommend trying to make the same requests using HttpURLConnection directly. If you see similar slow requests - which I believe is very likely to be the case - then there's not much that can be done in Volley about it. Perhaps the device's network connection is slow. You could also try another HttpStack instead of the default - Volley has an optional one based on Cronet, and there are many floating around the web based on OkHttp - to see if it performs better. But if a simple request to google.com is taking upwards of 6 seconds, as the logSlowRequests warning suggests, then I see no reason to believe it would be significantly better with any other HTTP library.

If for some reason you can consistently reproduce this with Volley but not HttpURLConnection, please reopen with more details. (Note that the log message is just a warning logged whenever a request is taking a while; HttpURLConnection won't do this, so you should track how long the requests are taking manually).

PanneerJan2 commented 1 year ago

Still I'm Facing Same Issue

jpd236 commented 1 year ago

(More details in https://github.com/google/volley/issues/444 - you can add further comments here rather than opening new issues)

One thing to note is that when this warning is logged, the requests are actually failing once (presumably a timeout) and then succeeding on the second try, since retryCount = 1. This is a little strange, in that if you're setting the timeout to 30000ms, it would seem it shouldn't be failing so quickly, although timeouts are a bit strange with HttpURLConnection and don't always work as you'd expect. Are you setting any timeouts on the HttpURLConnection? What happens if you do setConnectTimeout(30000) and setReadTimeout(30000) on the connection to match what Volley is doing with your retry policy?

It might also help to enable debug logging by running adb shell setprop log.tag.Volley VERBOSE and then force-stopping/restarting your app. This should add adb logging indicating each part of the request lifecycle, including any intermediate failures.