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

StrictMode: Not closing ApacheHttpClient Gzip Stream #38

Closed
chrisjenx opened this issue Aug 20, 2015 · 6 comments
Closed

StrictMode: Not closing ApacheHttpClient Gzip Stream #38

chrisjenx opened this issue Aug 20, 2015 · 6 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Milestone

Comments

@chrisjenx
Copy link

When calling network requests, it seems that you don't terminate your InputStreams safely leading to resource leaking.

Android 5.1.0,
Genemotion emulator
parse-android:1.10.1.

Personally I would move to using something like OKHttp out of choice as it saves effort on these issues which have already been solved.

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 okio.GzipSource.<init>(GzipSource.java:62)
            at com.squareup.okhttp.internal.http.HttpEngine.unzip(HttpEngine.java:650)
            at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:832)
            at com.squareup.okhttp.Call.getResponse(Call.java:274)
            at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
            at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
            at com.squareup.okhttp.Call.execute(Call.java:81)
            at com.parse.ParseOkHttpClient.executeInternal(ParseOkHttpClient.java:55)
            at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:155)
            at com.parse.ParsePlugins$1.intercept(ParsePlugins.java:111)
            at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:144)
            at com.parse.ParseHttpClient.execute(ParseHttpClient.java:119)
            at com.parse.ParseRequest$3.then(ParseRequest.java:195)
            at com.parse.ParseRequest$3.then(ParseRequest.java:192)
            at bolts.Task$15.run(Task.java:825)
            at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
            at bolts.Task.completeAfterTask(Task.java:816)
            at bolts.Task.continueWithTask(Task.java:628)
            at bolts.Task.continueWithTask(Task.java:639)
            at bolts.Task$13.then(Task.java:731)
            at bolts.Task$13.then(Task.java:719)
            at bolts.Task$15.run(Task.java:825)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
@grantland grantland added the type:bug Impaired feature or lacking behavior that is likely assumed label Aug 20, 2015
@grantland grantland added this to the 1.10.2 milestone Aug 20, 2015
@chrisjenx
Copy link
Author

Actually this might be a bug with OKHttp, but might be related to not closing the stream after parsing the result. As I don't see this issue personally with OKHttp when using it.

@wangmengyan95
Copy link
Contributor

@chrisjenx thank you so much for your issue. It seems a bug from our side not OKHttp. We forget to close the network stream in some cases. I have already send a PR, check #40 .
To make sure we actually fix the bug you mentioned, could you please tell us

  1. Are you using OKHttp library in your app?
  2. What Parse api you use when you see the output you mentioned.

@chrisjenx
Copy link
Author

@wangmengyan95 Hey,

I am using:

  • OKHttp 2.4.0
  • Okio 1.5.0
    I was doing a findQuery over the network. e.g:
    try {
        List<T> results = query.find();
        subscriber.onNext(results);
        subscriber.onCompleted();
      } catch (ParseException e) {
        subscriber.onError(e);
      }

@wangmengyan95
Copy link
Contributor

@chrisjenx thanks for you help, my PR has resolved this problem.

@chrisjenx
Copy link
Author

OK cool thanks @wangmengyan95

@aphexcx
Copy link

aphexcx commented Jan 19, 2016

Getting this too; I only noticed it because I run my apps in StrictMode with a penaltyDeath VmPolicy. Looks like there's still a corner where there's an unclosed stream.

Here's the stacktrace:

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 'close' not called
                                                              at dalvik.system.CloseGuard.open(CloseGuard.java:184)
                                                              at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:277)
                                                              at android.net.SSLCertificateSocketFactory.verifyHostname(SSLCertificateSocketFactory.java:189)
                                                              at android.net.SSLCertificateSocketFactory.createSocket(SSLCertificateSocketFactory.java:396)
                                                              at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:382)
                                                              at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
                                                              at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
                                                              at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
                                                              at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
                                                              at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
                                                              at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
                                                              at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
                                                              at com.parse.ParseApacheHttpClient.executeInternal(ParseApacheHttpClient.java:113)
                                                              at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:158)
                                                              at com.parse.ParseDecompressInterceptor.intercept(ParseDecompressInterceptor.java:30)
                                                              at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147)
                                                              at com.parse.ParsePlugins$1.intercept(ParsePlugins.java:115)
                                                              at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147)
                                                              at com.parse.ParseHttpClient.execute(ParseHttpClient.java:122)
                                                              at com.parse.ParseRequest$3.then(ParseRequest.java:135)
                                                              at com.parse.ParseRequest$3.then(ParseRequest.java:132)
                                                              at bolts.Task$15.run(Task.java:839)
                                                              at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
                                                              at bolts.Task.completeAfterTask(Task.java:830)
                                                              at bolts.Task.continueWithTask(Task.java:642)
                                                              at bolts.Task.continueWithTask(Task.java:653)
                                                              at bolts.Task$13.then(Task.java:745)
                                                              at bolts.Task$13.then(Task.java:733)
                                                              at bolts.Task$15.run(Task.java:839)
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
                                                              at java.lang.Thread.run(Thread.java:841)
W/System.err: StrictMode VmPolicy violation with POLICY_DEATH; shutting down.

My dependencies:

    compile 'com.parse:parse-android:1.12.0'
    compile 'com.parse.bolts:bolts-android:1.3.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants