markcorn / libs-for-android

Automatically exported from code.google.com/p/libs-for-android
Apache License 2.0
0 stars 0 forks source link

Occasional EOFException when reading cached file #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to load lots of previously cached images in a ListView by quickly 
scrolling back and forth
2. Some images will fail to load

What is the expected output? What do you see instead?
Files (in this case bitmaps) should be read from cache, but instead we get an 
EOFException like the following:

05-23 15:52:41.540: E/ImageLoader(32059): java.io.EOFException
05-23 15:52:41.540: E/ImageLoader(32059):   at 
libcore.io.Streams.readAsciiLine(Streams.java:203)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:547)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
libcore.net.http.HttpEngine.readResponse(HttpEngine.java:787)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:27
4)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java
:168)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.BitmapContentHandler.getContent(BitmapContentHand
ler.java:39)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.BitmapContentHandler.getContent(BitmapContentHand
ler.java:1)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.filecache.FileResponseCache$FileResponseCacheContentHandler.g
etContent(FileResponseCache.java:546)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.ImageLoader$ImageRequest.loadImage(ImageLoader.ja
va:763)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.ImageLoader$ImageRequest.execute(ImageLoader.java
:798)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.ImageLoader$ImageTask.doInBackground(ImageLoader.
java:992)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
com.google.android.imageloader.ImageLoader$ImageTask.doInBackground(ImageLoader.
java:1)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
android.os.AsyncTask$2.call(AsyncTask.java:264)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-23 15:52:41.540: E/ImageLoader(32059):   at 
java.lang.Thread.run(Thread.java:864)

It appears that the same problem occurs with not just bitmaps but also any 
other file.

Original issue reported on code.google.com by davidwu...@gmail.com on 23 May 2012 at 7:53

GoogleCodeExporter commented 8 years ago
I believe this is an Android issue.  I've hit the same problem with base 4.0.4 
and am guessing it's an HTTP keep-alive issue as it only happens on the second 
of back to back HttpsURLConnection use.  I verified that I'm reading the whole 
stream before disconnecting/returning to the pool, so will just disable 
http.keepAlive for now.  It's reproducible, but only happens about 25% of the 
time.

Original comment by pushbit on 21 Jun 2012 at 6:35

GoogleCodeExporter commented 8 years ago
Confirmed, same here. Adding a "Connection: Close" header solves the problem. 
Related discussion here: http://stackoverflow.com/a/13981774/454667

Original comment by bachi.in...@gmail.com on 25 Mar 2013 at 5:48

GoogleCodeExporter commented 8 years ago
Adding the following line
System.setProperty("http.keepAlive", "false");

just before creating the instance of the UrlConntion:
conn = (HttpURLConnection) url.openConnection();

Disables the keepalive via de client (android App). And also prevents the bug.

Original comment by barry.sc...@scarybarry.nl on 5 Apr 2013 at 3:06