{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/725","labels_url":"https://api.github.com/repos/bumptech/glide/issues/725/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/725/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/725/events","html_url":"https://github.com/bumptech/glide/issues/725","id":115114442,"number":725,"title":"\"Error reading data from stream\" from partially downloaded GIFs when used in list/gridview","user":{"login":"kenkyee","id":12235883,"avatar_url":"https://avatars.githubusercontent.com/u/12235883?v=3","gravatar_id":"","url":"https://api.github.com/users/kenkyee","html_url":"https://github.com/kenkyee","followers_url":"https://api.github.com/users/kenkyee/followers","following_url":"https://api.github.com/users/kenkyee/following{/other_user}","gists_url":"https://api.github.com/users/kenkyee/gists{/gist_id}","starred_url":"https://api.github.com/users/kenkyee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenkyee/subscriptions","organizations_url":"https://api.github.com/users/kenkyee/orgs","repos_url":"https://api.github.com/users/kenkyee/repos","events_url":"https://api.github.com/users/kenkyee/events{/privacy}","received_events_url":"https://api.github.com/users/kenkyee/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/duplicate","name":"duplicate","color":"cccccc"},{"url":"https://api.github.com/repos/bumptech/glide/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-04T18:14:21Z","updated_at":"2015-11-04T21:36:25Z","closed_at":null,"body":"I think this is probably because the okhttp thread to download the GIF was cancelled when the gridview/listview item was recycled.\r\n\r\nGlide should probably catch this exception and retry the download:\r\n```ruby\r\n11-04 12:22:46.977 27109-27251/com.sdktestapp W/GifResourceDecoder: Error reading data from stream\r\njava.io.InterruptedIOException\r\n    at com.android.okio.Deadline.throwIfReached(Deadline.java:56)\r\n    at com.android.okio.Okio$2.read(Okio.java:110)\r\n    at com.android.okio.RealBufferedSource.read(RealBufferedSource.java:48)\r\n    at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:442)\r\n    at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)\r\n    at java.io.FilterInputStream.read(FilterInputStream.java:118)\r\n    at com.bumptech.glide.util.ContentLengthInputStream.read(ContentLengthInputStream.java:65)\r\n    at com.bumptech.glide.util.ContentLengthInputStream.read(ContentLengthInputStream.java:60)\r\n    at com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream.fillbuf(RecyclableBufferedInputStream.java:132)\r\n    at com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream.read(RecyclableBufferedInputStream.java:309)\r\n    at java.io.InputStream.read(InputStream.java:162)\r\n    at com.bumptech.glide.load.resource.gif.GifResourceDecoder.inputStreamToBytes(GifResourceDecoder.java:105)\r\n    at com.bumptech.glide.load.resource.gif.GifResourceDecoder.decode(GifResourceDecoder.java:57)\r\n    at com.bumptech.glide.load.resource.gif.GifResourceDecoder.decode(GifResourceDecoder.java:26)\r\n    at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeGifWrapper(GifBitmapWrapperResourceDecoder.java:101)\r\n    at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeStream(GifBitmapWrapperResourceDecoder.java:87)\r\n    at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:71)\r\n    at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:61)\r\n    at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:22)\r\n    at com.bumptech.glide.load.engine.DecodeJob.decodeFromSourceData(DecodeJob.java:190)\r\n    at com.bumptech.glide.load.engine.DecodeJob.decodeSource(DecodeJob.java:177)\r\n    at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java:128)\r\n    at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java:122)\r\n    at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:101)\r\n    at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)\r\n    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n    at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n    at java.lang.Thread.run(Thread.java:818)\r\n    at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)\r\n```"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/153873367","html_url":"https://github.com/bumptech/glide/issues/725#issuecomment-153873367","issue_url":"https://api.github.com/repos/bumptech/glide/issues/725","id":153873367,"user":{"login":"TWiStErRob","id":2906988,"avatar_url":"https://avatars.githubusercontent.com/u/2906988?v=3","gravatar_id":"","url":"https://api.github.com/users/TWiStErRob","html_url":"https://github.com/TWiStErRob","followers_url":"https://api.github.com/users/TWiStErRob/followers","following_url":"https://api.github.com/users/TWiStErRob/following{/other_user}","gists_url":"https://api.github.com/users/TWiStErRob/gists{/gist_id}","starred_url":"https://api.github.com/users/TWiStErRob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TWiStErRob/subscriptions","organizations_url":"https://api.github.com/users/TWiStErRob/orgs","repos_url":"https://api.github.com/users/TWiStErRob/repos","events_url":"https://api.github.com/users/TWiStErRob/events{/privacy}","received_events_url":"https://api.github.com/users/TWiStErRob/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T21:36:25Z","updated_at":"2015-11-04T21:36:25Z","body":"DiskCacheStrategy will get smarter in Glide 4.0 with better defaults. I think this problem only comes up if you're loading megabytes sized GIFs on a very slow connection/from slow server. LargeMem shouldn't be necessary though.\r\n\r\n> If it detects this kind of error, it sounds like a truncated file from the networking library's cache\r\n\r\nGlide works with any networking library through [integration libraries](https://github.com/bumptech/glide/wiki/Integration-Libraries). The problem with your proposal is that each of those libraries throw a different exception or return a value indicating failure, so we can't know how and when to retry. Take a look at #520 for more info.\r\n\r\nI hope it's clearer now how this is not and should not be Glide's responsibilty. You can set up retries or write an integration library that returns a smart stream that retries if it fails to serve some bytes. OkHttp shouldn't return a partially cached stream and I think it doesn't do that anyway:\r\n\r\nOriginally you used the default RESULT cache which means that the stream was returned directly to the GIF decoder. While decoding the frames too much time has elapsed and an OkHttp deadline was reached. Maybe the GIF is too long or the delays are too big between frames.\r\nBy changing it to SOURCE you essentially told Glide to save that link first to the disk cache and then GIF decoder received a stream pointing to the disk which doesn't have a timeout.\r\n\r\n*In general we tend to expect too much from most of the libraries, expecting them to think of every use case and provide a simple method for that, but we can easily forget that people maintain libraries (with Glide it's mostly Sam alone). I'm a Glide user too, and I learned that I can Lego together small bits of it to achieve almost anything: see some of the issues here. It's also open source so PRs are warmly welcome ;)\r\n\r\nAnyway, thanks for the feedback! Good to see more critical thinkers out there. Remember that if you thought about it maybe the author did too, it's just not possible or it's not worth the effort.*"}}