okhttp: Strict Mode Error: Explicit termination method 'close' not called

Wounder if anyone else has seen this strict mode violation, it could be my own code but if it is I can’t see how.

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: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.access$100(RealCall.java:30)
                                                                          at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
                                                                          at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
                                                                          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)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (6 by maintainers)

Most upvoted comments

I have similar issue with v 3.11.0, see in logs this error:

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:180) at com.android.org.conscrypt.Platform.closeGuardOpen(Platform.java:282) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:316) at com.android.okhttp.Connection.connectTls(Connection.java:235) at com.android.okhttp.Connection.connectSocket(Connection.java:199) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java) at android.media.MediaHTTPConnection.seekTo(MediaHTTPConnection.java:211) at android.media.MediaHTTPConnection.readAt(MediaHTTPConnection.java:326) at android.media.MediaHTTPConnection.native_readAt(Native Method) at android.media.MediaHTTPConnection.readAt(MediaHTTPConnection.java:315) at android.media.IMediaHTTPConnection$Stub.onTransact(IMediaHTTPConnection.java:72) at android.os.Binder.execTransact(Binder.java:565)

I’m not sure, but everything seems to be working.

Please don’t call cache.close() until you’re completely done with your response cache.