Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes Not send request to sever but called onFailure method #725

Closed
Jimweb3 opened this issue Oct 31, 2014 · 13 comments
Closed

Sometimes Not send request to sever but called onFailure method #725

Jimweb3 opened this issue Oct 31, 2014 · 13 comments
Assignees
Labels
Milestone

Comments

@Jimweb3
Copy link

Jimweb3 commented Oct 31, 2014

My net is Ok , call a request not do the request but call onFailure?

@zhangxiao918
Copy link

you should tell us which version you use,and which android-platform you use.

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 4, 2014

Version 1.4.6 and android4.2.2

@smarek
Copy link
Member

smarek commented Nov 14, 2014

Well without further information, nobody will be able to help you. Closing this.
Next time provide LogCat outputs, your code (how you use AsyncHttpClient). Thanks

@smarek smarek closed this as completed Nov 14, 2014
@smarek smarek added this to the 1.4.7 milestone Nov 14, 2014
@smarek smarek self-assigned this Nov 14, 2014
@Jimweb3
Copy link
Author

Jimweb3 commented Nov 17, 2014

thanks for your reply, I use AsyncHttpClient in a Singleton,in my project the client has only one and it is static ,when my app started I get a new instance of client then I do get or post use it.But sometimes it not send request(because fiddler no request had saw) and call onFailure,then I try send request again but it also call onFailure,three or four times then it works fine.

@smarek
Copy link
Member

smarek commented Nov 17, 2014

What ExecutorService (ThreadPool) do you use? The default one?

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 17, 2014

donot change ThreadPool

@smarek
Copy link
Member

smarek commented Nov 17, 2014

Get and post here StackTrace of exception returned in onFailure method, or in LogCat, thanks

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 17, 2014

OK,because it is comes sometimes I will try to reappear it and get these exception here.Thank you.

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 19, 2014

I reappear it and get the exception,it is Time out exception,but not request had send and just call onFailure (I saw the fiddler not request send).Then try 2 or 3 times ,it is work, and the retry call onFailure also is Timed Out and time out quickly, like only one second.I set the time out use these code:

   client = new AsyncHttpClient();
    client.setTimeout(30 * 1000);
    client.setMaxConnections(6);

use android-async-http-1.4.5.jar

the StackTrace is :

Request Timed Out
org.apache.http.client.HttpResponseException: Request Timed Out
    at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:376)
    at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:101)
    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:112)
    at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:68)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)

some other are :

java.net.SocketTimeoutException
    at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
    at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
    at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:174)
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:188)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:178)
    at com.loopj.android.http.AsyncHttpResponseHandler.getResponseData(AsyncHttpResponseHandler.java:407)
    at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:372)
    at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:101)
    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:112)
    at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:68)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)

@smarek
Copy link
Member

smarek commented Nov 19, 2014

Without digging through the library or any possible problems you're dealing with, you should know, that in case of request timeout, you should retry the request
If you're sure this is problem of library/android version/device/network and not your server-side, then set the timeout low and handle "request timeouts" through repeating the requests. If you say that the request will go through on 3rd to 5th try, see if that is problem of slow network, or slow response from server.

One additional question, do you use HTTPS(443) or HTTP(80)

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 20, 2014

I reappear these time out many times ,it likes not normal request timeout because it is happen quickly,when I send request then I get time out and fiddler see no request had been send, no send by call onFailure and get the exception is timeout ,if it is the server-side error ,it may happens when request had send 30 seconds because I set

client.setTimeout(30 * 1000);

I use http not https.and these requests I send in fragment.

@smarek
Copy link
Member

smarek commented Nov 20, 2014

As I said, if you suffer from the SocketTimeoutExceptions, you should handle them gracefully and eg. retry them. Does this happen to you on multiple devices and separate networks? I mean, have you tested it's not problem of your current development environment?

Good you use http (unless you're sending some sensitive data over the non-encrypted channel), https suffers sometimes from this problem (i've seen it reported already)

@Jimweb3
Copy link
Author

Jimweb3 commented Nov 21, 2014

Thank you . I had do retry when I get SocketTimeoutExceptions. But the question is why there is not request had send and call onFailure method, any way can fix it ? Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants