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

CloseGuard error after EOFException #116

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

CloseGuard error after EOFException #116

wonderfly opened this issue Jan 9, 2015 · 21 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@wonderfly
Copy link
Contributor

From yan...@google.com on May 19, 2012 07:09:00

Version of google-http-java-client (e.g. 1.5.0-beta)? 1.9.0-beta Java environment (e.g. Java 6, Android 2.3, App Engine)? Android Describe the problem. Reported by aalbert:

When this exception is thrown:
05-18 16:18:10.546 895 1825 E App: java.io.EOFException
05-18 16:18:10.546 895 1825 E App: at libcore.io.Streams.readAsciiLine(Streams.java:203)
05-18 16:18:10.546 895 1825 E App: at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:582)
05-18 16:18:10.546 895 1825 E App: at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836)
05-18 16:18:10.546 895 1825 E App: at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
05-18 16:18:10.546 895 1825 E App: at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
05-18 16:18:10.546 895 1825 E App: at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:37)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:89)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:814)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.googleapis.json.GoogleJsonResponseException.execute(GoogleJsonResponseException.java:182)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:115)
05-18 16:18:10.546 895 1825 E App: at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:112)

The underlying connection is not closed properly and we get a CloseGuard error:

05-18 16:19:10.343 895 904 E StrictMode: at dalvik.system.CloseGuard.open(CloseGuard.java:184)
05-18 16:19:10.343 895 904 E StrictMode: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:287)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:210)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:293)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:243)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
05-18 16:19:10.343 895 904 E StrictMode: at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
05-18 16:19:10.343 895 904 E StrictMode: at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:88) How would you expect it to be fixed? No CloseGuard error.

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

@wonderfly wonderfly added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. imported labels Jan 9, 2015
@wonderfly wonderfly self-assigned this Jan 9, 2015
@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 21, 2012 11:05:54

The fix for this is to call response.disconnect / response.close in HttpResponseException(HttpResponse, String message). But this can only be done after we update all internal references to that deprecated method and delete HttpResponse.getResponse.

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 31, 2012 08:10:23

http://codereview.appspot.com/6225045/

Status: Fixed

@wonderfly
Copy link
Contributor Author

From alexey.v...@gmail.com on September 26, 2012 02:16:35

I still get the same error in last version of library

@wonderfly
Copy link
Contributor Author

From yan...@google.com on September 26, 2012 04:04:29

Can you please provide a stack trace? Thanks!

Status: RequestedFeedback

@wonderfly
Copy link
Contributor Author

From alexey.v...@gmail.com on October 09, 2012 22:07:26

Sorry for late response. Im using 1.11.0-beta

java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:37)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:101)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:991)
at me.lyft.android.api.LyftApi.execute(LyftApi.java:76)
at me.lyft.android.api.LyftApi.requestRide(LyftApi.java:191)
at me.lyft.android.api.LyftApi$5.call(LyftApi.java:198)
at me.lyft.android.api.LyftApi$5.call(LyftApi.java:195)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

@wonderfly
Copy link
Contributor Author

From alexey.v...@gmail.com on October 11, 2012 10:01:39

Is there any way how i can fix it? May be I should use some sort of close stream method?

@wonderfly
Copy link
Contributor Author

From alexey.v...@gmail.com on October 15, 2012 03:40:36

I've ensured that i always call response.disconnect after using it. But error is still there.

@wonderfly
Copy link
Contributor Author

From yiyuanh...@gmail.com on October 15, 2012 08:46:26

I got the same problem :
10-15 23:40:50.306: I/yiyuan(1282): url 11111
10-15 23:40:50.306: I/yiyuan(1282): url 22222hahhahahha
10-15 23:40:50.726: W/System.err(1282): java.io.EOFException
10-15 23:40:50.746: W/System.err(1282): at libcore.io.Streams.readAsciiLine(Streams.java:203)
10-15 23:40:50.746: W/System.err(1282): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:547)
10-15 23:40:50.756: W/System.err(1282): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:787)
10-15 23:40:50.766: W/System.err(1282): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
10-15 23:40:50.766: W/System.err(1282): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
10-15 23:40:50.786: W/System.err(1282): at com.HttpDownloader.downloadGet(HttpDownloader.java:105)

my code as follows :

public static String downloadGet(String urlStr) throws Exception {
    StringBuffer sb = new StringBuffer();
    BufferedReader br;
    String line = null;
    try 
    {
    System.setProperty("http.keepAlive", "false");  
    Log.i("yiyuan","will load url :" + urlStr);
    URL url = new URL(urlStr);
    Log.i("yiyuan"," url 11111" );
    HttpURLConnection connect = (HttpURLConnection) url.openConnection();
    Log.i("yiyuan"," url 22222hahhahahha" );
    InputStream inputStr = connect.getInputStream() ;
    Log.i("yiyuan"," url 8888" );
    InputStreamReader inputRead = new InputStreamReader(inputStr) ;
    Log.i("yiyuan"," url 9999" );
    br = new BufferedReader(inputRead );
    Log.i("yiyuan"," url 33333" );
    while((line = br.readLine()) != null) 
    {
        Log.i("yiyuan"," url 44444" );
        sb.append(line);
    }
    inputRead.close();
    connect.disconnect();

    }
    catch (Exception e) {    
    e.printStackTrace();   
    Log.i("yiyuan"," url error error " );
    }
    finally
    {  
    }    

    Log.i("yiyuan"," url 5555" );
    return sb.toString();
}

@wonderfly
Copy link
Contributor Author

From yan...@google.com on October 16, 2012 05:43:39

Status: Accepted
Owner: yan...@google.com
Cc: rmis...@google.com

@wonderfly
Copy link
Contributor Author

From yiyuanh...@gmail.com on October 16, 2012 06:34:05

I found that , I give the wrong url , which case the error happen ; while I change , it works well now !

@wonderfly
Copy link
Contributor Author

From yan...@google.com on October 30, 2012 07:39:31

Cc: ngmic...@google.com
Labels: -Milestone-Version1.10.0 Milestone-Version1.12.0

@wonderfly
Copy link
Contributor Author

From andy.den...@gmail.com on November 01, 2012 07:40:21

I'm seeing a very similar (maybe same?) issue with StrictMode enabled for Android, in conjunction with AdMob. This happens with every ad refresh:

11-01 14:38:45.081: E/StrictMode(1657): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
11-01 14:38:45.081: E/StrictMode(1657): java.lang.Throwable: Explicit termination method 'end' not called
11-01 14:38:45.081: E/StrictMode(1657): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
11-01 14:38:45.081: E/StrictMode(1657): at java.util.zip.Inflater.(Inflater.java:82)
11-01 14:38:45.081: E/StrictMode(1657): at java.util.zip.GZIPInputStream.(GZIPInputStream.java:96)
11-01 14:38:45.081: E/StrictMode(1657): at java.util.zip.GZIPInputStream.(GZIPInputStream.java:81)
11-01 14:38:45.081: E/StrictMode(1657): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:512)
11-01 14:38:45.081: E/StrictMode(1657): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:805)
11-01 14:38:45.081: E/StrictMode(1657): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
11-01 14:38:45.081: E/StrictMode(1657): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
11-01 14:38:45.081: E/StrictMode(1657): at com.google.ads.internal.f.b(SourceFile:460)
11-01 14:38:45.081: E/StrictMode(1657): at com.google.ads.internal.f.run(SourceFile:430)
11-01 14:38:45.081: E/StrictMode(1657): at java.lang.Thread.run(Thread.java:856)

@wonderfly
Copy link
Contributor Author

From andy.den...@gmail.com on November 01, 2012 07:44:02

FYI, here's a fix that the Square team made: https://github.com/square/okhttp/pull/24/files

@wonderfly
Copy link
Contributor Author

From yan...@google.com on November 01, 2012 14:29:18

Labels: -Milestone-Version1.12.0 Milestone-Version1.13.0

@wonderfly
Copy link
Contributor Author

From sebastia...@gmail.com on November 01, 2012 20:22:51

Perhaps related to http://stackoverflow.com/questions/13182519/spring-rest-template-usage-causes-eofexception - which creates EOFExceptions

@wonderfly
Copy link
Contributor Author

From alexey.v...@gmail.com on November 05, 2012 05:22:57

This is defenetly somehow connected with keepAlive connections.

When I use: System.setProperty("http.keepAlive", "false"); problems disappears.

But from my understanding keep alive connections are greatly increase performance so it is better not to disable them.

Im also awere that keep alive should be disabled for old versions, but my device is Jelly Bean.

@wonderfly
Copy link
Contributor Author

From yan...@google.com on December 11, 2012 05:24:48

Labels: -Priority-Critical -Milestone-Version1.13.0 Priority-High

@wonderfly
Copy link
Contributor Author

From supp...@stacktype.com on April 18, 2013 11:35:39

I am using cloud endpoints and face this error,

Jars used
google-http-client-1.14.1-beta.jar
google-api-client-android-1.14.1-beta.jar

04-17 23:34:48.526: W/AbstractGoogleClient(27540): Application name is not set. Call Builder#setApplicationName.
04-17 23:34:48.616: E/class com.stacktype.addtodroid2.SendToDeviceActivity(27540): An error occured while sending the message
04-17 23:34:48.616: W/System.err(27540): java.io.EOFException
04-17 23:34:48.616: W/System.err(27540): at libcore.io.Streams.readAsciiLine(Streams.java:203)
04-17 23:34:48.616: W/System.err(27540): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
04-17 23:34:48.616: W/System.err(27540): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
04-17 23:34:48.616: W/System.err(27540): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
04-17 23:34:48.616: W/System.err(27540): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
04-17 23:34:48.616: W/System.err(27540): at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:37)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:95)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:980)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
04-17 23:34:48.616: W/System.err(27540): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
04-17 23:34:48.616: W/System.err(27540): at com.stacktype.addtodroid2.ServerUtilities.postMessage(ServerUtilities.java:176)
04-17 23:34:48.616: W/System.err(27540): at com.stacktype.addtodroid2.SendToDeviceActivity$SendMessageToService.doInBackground(SendToDeviceActivity.java:94)
04-17 23:34:48.616: W/System.err(27540): at com.stacktype.addtodroid2.SendToDeviceActivity$SendMessageToService.doInBackground(SendToDeviceActivity.java:1)
04-17 23:34:48.626: W/System.err(27540): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-17 23:34:48.626: W/System.err(27540): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-17 23:34:48.626: W/System.err(27540): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-17 23:34:48.626: W/System.err(27540): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-17 23:34:48.626: W/System.err(27540): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-17 23:34:48.626: W/System.err(27540): at java.lang.Thread.run(Thread.java:856)

@wonderfly
Copy link
Contributor Author

From itop...@gmail.com on October 11, 2013 00:37:38

I got this in Android 4.2

W/System.err(26908): java.io.EOFException
W/System.err(26908): at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:206)
W/System.err(26908): at java.util.zip.GZIPInputStream.verifyCrc(GZIPInputStream.java:191)
W/System.err(26908): at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:177)
W/System.err(26908): at java.io.InputStream.read(InputStream.java:163)
W/System.err(26908): at com.android.volley.toolbox.BasicNetwork.entityToBytes(BasicNetwork.java:223)
W/System.err(26908): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:106)
W/System.err(26908): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)

@wonderfly
Copy link
Contributor Author

From deepesh...@gmail.com on April 21, 2014 02:07:25

I got this in Android 4.4

java.util.concurrent.TimeoutException: com.android.internal.os.BinderInternal$GcWatcher.finalize() timed out after 10 seconds
at dalvik.system.CloseGuard.close(CloseGuard.java:195)
at java.io.FileInputStream.close(FileInputStream.java:115)
at java.io.FileInputStream.finalize(FileInputStream.java:142)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
at java.lang.Thread.run(Thread.java:841)

@Kester4android
Copy link

if (Build.VERSION.SDK != null
&& Build.VERSION.SDK_INT > 13) {
urlConnect.setRequestProperty("Connection", "close");
}

@wonderfly wonderfly removed their assignment May 20, 2016
@mattwhisenhunt mattwhisenhunt added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed Priority-High labels Dec 11, 2017
@mattwhisenhunt mattwhisenhunt added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Mar 12, 2018
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 6, 2020
@JustinBeckwith JustinBeckwith self-assigned this Feb 1, 2021
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
* Update release process for Javadoc update

* Add copyright and license
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants