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

EOF Exception Android API 14+ , URLConnection #213

Closed
wonderfly opened this issue Jan 9, 2015 · 12 comments

Comments

Projects
None yet
7 participants
@wonderfly
Copy link
Contributor

commented Jan 9, 2015

From chris.mark.jenkins@gmail.com on March 27, 2013 08:55:20

Version of google-http-java-client (e.g. 1.5.0-beta)? 1.13.1-beta Java environment (e.g. Java 6, Android 2.3, App Engine)? Java 6, Android 4.X (Galaxy Nexus, Nexus 4, Nexus 7, Samsung S2) (Real devices NOT AVD). Describe the problem. Connection spoiling the header by leaving an old connection open. See attached forum post: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/e_FExl6jl90 This is a sporadic bug, but "looks" like the connection terminated the connection randomly when it appears that the old connection is not "cleaned" properly. How would you expect it to be fixed? As mentioned in the forum post I am fixing the request with the following method when creating the request.

public static void tryToFixNetHttpRequest(final HttpHeaders headers)
{
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            try
            {
                headers.set("Connection", "close");
            }
            catch (Exception e)
            {
            }
}

So far I am yet to see the error again. We can of course use this as a work around on android, but a better solution would be more appropriate.

Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=213

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From dorian.c...@googlemail.com on March 27, 2013 08:58:57

I seem to only be getting this on POST requests and I think someone also mentioned this in the link mentioned above.

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From dorian.c...@googlemail.com on March 28, 2013 04:22:08

Im getting this on a Nexus 4 running 4.2.2

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From dorian.c...@googlemail.com on April 08, 2013 03:39:59

The fix works but means the fix for this https://code.google.com/p/android/issues/detail?id=29509 bug cannot be implemented. When a carrier uses a proxy for network data and an https call is made over 3g the socket is closed automatically using HttpUrlConnection. It seems JellyBean + HttpUrlConnection is not a happy bunny. :(

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From mbar...@secureapps.us on November 13, 2013 16:48:20

Still getting this compiling with android 4.4, so this has not been fixed.

And yes, seems to only work on POST requests. In particular, if prior GET requests are issued with keep-alive connections, a POST request, after writing any data, will raise an EOF exception when trying to read the response headers.

This can be avoided by setting the connection to close on both the GET and POST requests. But as was pointed out, this conflicts with another issue.

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From gshi...@quikr.com on November 13, 2013 22:15:06

I think u should integrate httpclient . http://hc.apache.org/httpclient-3.x/

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From james.w...@gmail.com on May 20, 2014 22:28:33

This seems to be specific to the underlying java.net.HttpURLConnection. Unlike #5, I can not reproduce this issue on Android 4.4 API 19 (KitKat). Perhaps there are other issues involved which cause similar symptoms?

I am able to reproduce this 100% of the time on Android 4.3 API 18 (JB MR2) by sending a POST request and then idling the application for 10 minutes. This idle duration depends on the server's keepalive timeout. After a sufficiently long idle period, the next 2-4 POST requests fail with EOFExceptions before requests begin to work again.

Calling HttpURLConnection's setRequestProperty("Connection", "close") prevents this bug from happening.

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From james.w...@gmail.com on May 21, 2014 18:14:31

I was able to work around this problem using a retry mechanism. The trick is to ensure that the number of retries corresponds with the "http.maxConnections" system property. I shared the code here: http://stackoverflow.com/a/23795099/204480

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2015

From grob....@gmail.com on July 30, 2014 10:04:29

I had this behavior on several Devices from Samsung. HTC, Asus and LG didn't have this problem. All Devices are 4.1.2 and above.

The workaround from the OP saved me. Thanks a lot.

@rayvo

This comment has been minimized.

Copy link

commented Jun 12, 2015

I got my code works only on my local machine 192.168..X.X:8080 Tomcat Server.
But when I run this code on a real server with a public IP X.X.X.X:80...I got this error.

I tried your solution with "http.maxConnections" will send a file with maxconnections number to the server.....and still cannot solve the problem. ALTHOUGH ERROR IS STILL THERE.

Any suggestion?
Thanks

@soulfly

This comment has been minimized.

Copy link

commented Jan 29, 2016

The fix with setRequestProperty("Connection", "close") should work, but I have a question: it means that we can't use Connection: keep-alive, so every new request will be a new connection to server?

@vaughandroid

This comment has been minimized.

Copy link

commented May 17, 2016

Over a year and no movement on this? 👎

@sduskis

This comment has been minimized.

Copy link

commented Mar 8, 2019

This issue is super old. I'm going to close this. If someone comes along, and sees this, please open a new issue.

@sduskis sduskis closed this Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.