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

ConnectionPoolTimeoutException incase of too many 404 in BinaryResponseHttpResponseHandler #267

Closed
oronno opened this issue Jul 17, 2013 · 3 comments

Comments

@oronno
Copy link

oronno commented Jul 17, 2013

When too many request(upto 10 tested) sent simultaneously for binary data with BinaryResponseHttpResponseHandler and 404 (Not found) response from server; Then any other http request serving by AsyncHttpResponseHandler got ConnectionPoolTimeoutException. Seems, connection is not closing incase of error/404 response, cause pool overflow.

Here, is the exception:

    java.net.ConnectException
    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:126)
    at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1027)
    Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection
    at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:353)
    at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:238)
    at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:175)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:325)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:76)
    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:95)
    ... 7 more
@oronno
Copy link
Author

oronno commented Jul 19, 2013

I can figure out the problem and found solution.
BinaryHttpResponseHandler by default only allow "image/jpeg", "image/png" content type, and ABORT processing response if Content-Type is not so ( jpg or png). So, if server return 404 status with content type of html/json incase of image not found, it cause connection still open for certain period of time and cause ConnectionPoolTimeoutException when there are many request sent simultaneously.
In my case, server would return 404 with json response incase of image not found. So I use
BinaryHttpResponseHandler(String[] allowedContentTypes) constructor and change the mAllowedContentTypes to:
{
"image/jpeg",
"image/png",
"application/json"
} to get rid of this problem.

@oronno oronno closed this as completed Jul 19, 2013
@Visualrainy
Copy link

why not close the connection?

@Visualrainy
Copy link

if other reason due to the errorcode not 200 ,may exist the same problem

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

No branches or pull requests

2 participants