Glide Version: 3.7.0
OkHttp3 Version: 3.0.1 (same for 3.4.1)
Integration libraries: okhttp3-1.4.0
Device/Android Version: Genymotion Google Nexus 6 5.0.0
Issue details / Repro steps / Use case background:
If Glide is used together with OkHttp disk cache instead of the Glide disk cache the cancelation mechanism (while scrolling through a list of images) of Glide leads to an Thread.interrupt(). If the thread is interrupted while OkHttp DiskLruCache is writing an entry to the disk it leads to a corruption of the file journal. OkHttp doesn't recover from this state until the app is restarted with the effect that caching stops working.
I don't know whether this problem should be solved on the Glide or OkHttp side. This is why I create issue tickets in both projects: You can find the related Glide issue ticket here
Glide load line / GlideModule (if any) / list Adapter code (if any):
disable Glide disk cache in every request
new GlideRequestBuilder(requestManager.load(url).diskCacheStrategy(DiskCacheStrategy.NONE));
enabling OkHttp disk cache in the GlideModule
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.cache(new Cache(new File(context.getCacheDir(), "okhttp_image_disk_cache"), DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build()));
The cancelation calling stack is as follows:
GenericRequest.cancel()
Engine$LoadStatus.cancel()
EngineJob.removeCallback()
EngineJob.cancel()
FutureTask.cancel()
Thread.interrupt()
Right now OkHttp does not expect to be interrupted and so it鈥檒l break if you interrupt it. We're planning on fixing that with our 2nd generation disk cache.
Tracking here: https://github.com/square/okhttp/issues/1902
Most helpful comment
Right now OkHttp does not expect to be interrupted and so it鈥檒l break if you interrupt it. We're planning on fixing that with our 2nd generation disk cache.