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

Android StrictMode violation for Gzip response not closing InputStream #281

Closed
johnfrey99 opened this issue Aug 14, 2013 · 4 comments
Closed
Milestone

Comments

@johnfrey99
Copy link

Using Retrofit with OkClient when I turn on StrictMode as follows

        StrictMode.setVmPolicy(
                new StrictMode.VmPolicy.Builder()
                        .detectLeakedSqlLiteObjects()
                        .detectLeakedClosableObjects()
                        .penaltyLog()
                        .build()
        );

I get the following violation in the log...

08-13 11:20:09.786    2028-2037/com.airstrip.one E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
        java.lang.Throwable: Explicit termination method 'end' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:184)
        at java.util.zip.Inflater.<init>(Inflater.java:82)
        at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
        at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
        at com.squareup.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:453)
        at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:650)
        at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:396)
        at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:345)
        at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:546)
        at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:148)
        at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:65)
        at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:33)
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:241)
        at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:182)
@swankjesse
Copy link
Collaborator

Still an issue? Does this occur on a redirect? Generally OkHttp doesn't close it's input stream; that's the application layer's job. But sometimes it does, as when it encounters a redirect.

@johnfrey99
Copy link
Author

Yeah it's still an issue. Perhaps this ball belong's in retrofit's court then? I don't know... when my server guys turn off the gzip responses I don't see any violations. I can see in the retrofit GsonConverter where it's creating a new InputStreamReader from the response body and closing it in a finally block.

@swankjesse
Copy link
Collaborator

We need a test case.

@JakeWharton
Copy link
Collaborator

This was determined to be a Retrofit bug.

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

3 participants