artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

CloseGuard error after EOFException #116

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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:27
4)
05-18 16:18:10.546   895  1825 E App:   at 
libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.jav
a:486)
05-18 16:18:10.546   895  1825 E App:   at 
libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.j
ava:134)
05-18 16:18:10.546   895  1825 E App:   at 
com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:3
7)
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(Google
JsonResponseException.java:182)
05-18 16:18:10.546   895  1825 E App:   at 
com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleCli
ent.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(OpenSSLSo
cketImpl.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(HttpsURLCo
nnectionImpl.java:478)
05-18 16:19:10.343   895   904 E StrictMode:    at 
libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionIm
pl.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 reported on code.google.com by yan...@google.com on 19 May 2012 at 2:09

GoogleCodeExporter commented 9 years ago
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.

Original comment by rmis...@google.com on 21 May 2012 at 6:05

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/6225045/

Original comment by rmis...@google.com on 31 May 2012 at 3:10

GoogleCodeExporter commented 9 years ago
I still get the same error in last version of library 

Original comment by alexey.v...@gmail.com on 26 Sep 2012 at 9:16

GoogleCodeExporter commented 9 years ago
Can you please provide a stack trace?  Thanks!

Original comment by yan...@google.com on 26 Sep 2012 at 11:04

GoogleCodeExporter commented 9 years ago
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.<init>(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)

Original comment by alexey.v...@gmail.com on 10 Oct 2012 at 5:07

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

Original comment by alexey.v...@gmail.com on 11 Oct 2012 at 5:01

GoogleCodeExporter commented 9 years ago
I've ensured that i always call response.disconnect after using it. But error 
is still there.

Original comment by alexey.v...@gmail.com on 15 Oct 2012 at 10:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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:27
4)
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();
    }

Original comment by yiyuanh...@gmail.com on 15 Oct 2012 at 3:46

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 16 Oct 2012 at 12:43

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

Original comment by yiyuanh...@gmail.com on 16 Oct 2012 at 1:34

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 30 Oct 2012 at 2:39

GoogleCodeExporter commented 9 years ago
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.<init>(Inflater.java:82)
11-01 14:38:45.081: E/StrictMode(1657):     at 
java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
11-01 14:38:45.081: E/StrictMode(1657):     at 
java.util.zip.GZIPInputStream.<init>(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:27
4)
11-01 14:38:45.081: E/StrictMode(1657):     at 
libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.jav
a: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)

Original comment by andy.den...@gmail.com on 1 Nov 2012 at 2:40

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

Original comment by andy.den...@gmail.com on 1 Nov 2012 at 2:44

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 1 Nov 2012 at 9:29

GoogleCodeExporter commented 9 years ago
Perhaps related to 
http://stackoverflow.com/questions/13182519/spring-rest-template-usage-causes-eo
fexception - which creates EOFExceptions

Original comment by sebastia...@gmail.com on 2 Nov 2012 at 3:22

GoogleCodeExporter commented 9 years ago
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.

Original comment by alexey.v...@gmail.com on 5 Nov 2012 at 1:22

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 11 Dec 2012 at 1:24

GoogleCodeExporter commented 9 years ago
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:28
3)
04-17 23:34:48.616: W/System.err(27540):    at 
libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.jav
a:495)
04-17 23:34:48.616: W/System.err(27540):    at 
libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.j
ava:134)
04-17 23:34:48.616: W/System.err(27540):    at 
com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:3
7)
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.executeUnp
arsed(AbstractGoogleClientRequest.java:412)
04-17 23:34:48.616: W/System.err(27540):    at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnp
arsed(AbstractGoogleClientRequest.java:345)
04-17 23:34:48.616: W/System.err(27540):    at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(Ab
stractGoogleClientRequest.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.doInBackgrou
nd(SendToDeviceActivity.java:94)
04-17 23:34:48.616: W/System.err(27540):    at 
com.stacktype.addtodroid2.SendToDeviceActivity$SendMessageToService.doInBackgrou
nd(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)

Original comment by supp...@stacktype.com on 18 Apr 2013 at 6:35

GoogleCodeExporter commented 9 years ago
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)

Original comment by itop...@gmail.com on 11 Oct 2013 at 7:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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)

Original comment by deepesh...@gmail.com on 21 Apr 2014 at 9:07