Picasso: Explicit termination method 'close' not called

Created on 2 Mar 2016  Â·  12Comments  Â·  Source: square/picasso

I'm using 2.5.2, and run with strictmode_vm, but sometimes app crashed by the below stack:

java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:180)
at java.io.FileOutputStream.(FileOutputStream.java:89)
at java.io.FileOutputStream.(FileOutputStream.java:72)
at com.android.okhttp.okio.Okio.sink(Okio.java:174)
at com.android.okhttp.internal.io.FileSystem$1.sink(FileSystem.java:49)
at com.android.okhttp.internal.DiskLruCache$Editor.newSink(DiskLruCache.java:876)
at com.android.okhttp.Cache$CacheRequestImpl.(Cache.java:410)
at com.android.okhttp.Cache.put(Cache.java:236)
at com.android.okhttp.Cache.-wrap0(Cache.java)
at com.android.okhttp.Cache$1.put(Cache.java:142)
at com.android.okhttp.internal.http.HttpEngine.maybeCache(HttpEngine.java:566)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:841)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:448)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:393)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:506)
at com.squareup.picasso.UrlConnectionDownloader.load(SourceFile:93)
at com.squareup.picasso.NetworkRequestHandler.load(SourceFile:47)
at com.squareup.picasso.BitmapHunter.hunt(SourceFile:206)
at com.squareup.picasso.BitmapHunter.run(SourceFile:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.squareup.picasso.Utils$PicassoThread.run(SourceFile:411)

All 12 comments

Any help?

This is happening to me as well. Would like to know if it is going to be addressed in the next release.

If it is any help I believe it might be related to having the following items set:
Picasso.with(getContext()).invalidate(stringUrl)
Picasso.with(getContext()).load(stringUrl).networkPolicy(NetworkPolicy.NO_CACHE)......

For this particular image I don't want to get it from Picasso cache or Network cache as the server gives me back a url for an image that may have changed since last request. That processing is working perfectly but I do see the stack trace reported.

We're pretty confident this is an OkHttp bug present inside of Android. Embed the latest OkHttp jar in your app to fix it.

Jake,

Thanks, adding
compile 'com.squareup.okhttp3:okhttp:3.2.0'
to my build.gradle took care of the issue. Appears to be working great now.

One new issue - it works great for a debug build but for a build using proguard the error reappears. I know just enough about proguard to be dangerous.

Is there a proguard-rules.pro line or two I can use to force those builds to use the newer version of OkHttp as well?

We're not proguard users so I'm not sure. You'll want to retain the class
name of okhttp3.OkHttpClient at the very least. Beyond that I can't offer
any actionable advice.

On Tue, Mar 22, 2016 at 4:22 PM MKevin3 [email protected] wrote:

One new issue - it works great for a debug build but for a build using
proguard the error reappears. I know just enough about proguard to be
dangerous.

Is there a proguard-rules.pro line or two I can use to force those builds
to use the newer version of OkHttp as well?

—
You are receiving this because you commented.

Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/1305#issuecomment-200004660

Switch to 2.6.0-SNAPSHOT and manually link to OkHTTP and OKIO and all is fine for proguard builds as well. Product is several months out for release so hopefully 2.6 official release by then.

I'm working on it.

On Tue, Mar 22, 2016 at 4:49 PM MKevin3 [email protected] wrote:

Switch to 2.6.0-SNAPSHOT and manually link to OkHTTP and OKIO and all is
fine for proguard builds as well. Product is several months out for release
so hopefully 2.6 official release by then.

—
You are receiving this because you commented.

Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/1305#issuecomment-200018794

@JakeWharton Is this StrictMode stack trace the same issue described here? It lists a FileInputStream instead of FileOutputStream and I use OkHttp3Downloader. I also don't use the Android version of OkHttp and have it as a compile dependency instead.

I'm using Picasso 2.5.2 and OkHttp 3.2.0.

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:180)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at okio.Okio.source(Okio.java:163)
    at okhttp3.internal.io.FileSystem$1.source(FileSystem.java:44)
    at okhttp3.internal.DiskLruCache$Entry.snapshot(DiskLruCache.java:1004)
    at okhttp3.internal.DiskLruCache.get(DiskLruCache.java:431)
    at okhttp3.Cache.get(Cache.java:193)
    at okhttp3.Cache$1.get(Cache.java:143)
    at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:198)
    at okhttp3.RealCall.getResponse(RealCall.java:240)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at com.jakewharton.picasso.OkHttp3Downloader.load(OkHttp3Downloader.java:126)
    at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:47)
    at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
    at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.util.concurrent.ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)
    at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)

If it isn't the same problem, I can create another issue.

+1 for @austynmahoney

I'm using Picasso 2.4.0 and OkHttp 3.2.0.
+1 for @austynmahoney

We no longer support HttpURLConnection on master. Closing.

Was this page helpful?
0 / 5 - 0 ratings