flutter_downloader
flutter_downloader copied to clipboard
SocketTimeoutException on Android
I got java.net.SocketTimeoutException during downloading the file an. on Android:
java.net.SocketTimeoutException: timeout
2020-05-15 10:24:23.852 10660-10973/com.myapp W/System.err: at com.android.okhttp.okio.Okio$3.newTimeoutException(Okio.java:212)
2020-05-15 10:24:23.853 10660-10973/com.myapp W/System.err: at com.android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.java:250)
2020-05-15 10:24:23.853 10660-10973/com.myapp W/System.err: at
I see that the reason is in your DownloadWorker.java class. Timeout is 15 seconds. How to increase it?
httpConn.setConnectTimeout(15000); httpConn.setReadTimeout(15000);
https://github.com/fluttercommunity/flutter_downloader/blob/master/android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java
Thank you.
Having the same problem Overriding with HttpOverrides is not work
@shunnokw I forked flutter_downloader and increased timeout to 45 seconds. You can use it as a temporary solution: https://github.com/valerybodak/flutter_downloader
I am also facing the same problem. API takes time to respond as it has a lot of data to process and send the response as the blob. There should be some property to set from flutter end for this plugin where timeout can be set. As large data takes time to process and it is a generic scenario that might happen anytime. Request to please provide some property to manage timeout easily.
/flutter (25273): 0 I/flutter (25273): DownloadTaskStatus(2) D/DownloadWorker(25273): Update notification: {notificationId: 84, title: http://192.168.1.21:3000/test.ipynb, status: 4, progress: -1} I/flutter (25273): -1 I/flutter (25273): DownloadTaskStatus(4) W/System.err(25273): java.net.SocketTimeoutException: timeout W/System.err(25273): at com.android.okhttp.okio.Okio$3.newTimeoutException(Okio.java:225) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.java:263) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:217) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:317) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:311) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:207) W/System.err(25273): at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:395) W/System.err(25273): at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:146) W/System.err(25273): at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:900) W/System.err(25273): at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:772) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542) W/System.err(25273): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:294) W/System.err(25273): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:208) W/System.err(25273): at androidx.work.Worker$1.run(Worker.java:85) W/System.err(25273): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err(25273): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err(25273): at java.lang.Thread.run(Thread.java:923) W/System.err(25273): Caused by: java.net.SocketException: Socket closed W/System.err(25273): at java.net.SocketInputStream.read(SocketInputStream.java:209) W/System.err(25273): at java.net.SocketInputStream.read(SocketInputStream.java:144) W/System.err(25273): at com.android.okhttp.okio.Okio$2.read(Okio.java:145) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:213) W/System.err(25273): ... 16 more
/flutter (25273): 0 I/flutter (25273): DownloadTaskStatus(2) D/DownloadWorker(25273): Update notification: {notificationId: 84, title: http://192.168.1.21:3000/test.ipynb, status: 4, progress: -1} I/flutter (25273): -1 I/flutter (25273): DownloadTaskStatus(4) W/System.err(25273): java.net.SocketTimeoutException: timeout W/System.err(25273): at com.android.okhttp.okio.Okio$3.newTimeoutException(Okio.java:225) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.java:263) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:217) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:317) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:311) W/System.err(25273): at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:207) W/System.err(25273): at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:395) W/System.err(25273): at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:146) W/System.err(25273): at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:900) W/System.err(25273): at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:772) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411) W/System.err(25273): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542) W/System.err(25273): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:294) W/System.err(25273): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:208) W/System.err(25273): at androidx.work.Worker$1.run(Worker.java:85) W/System.err(25273): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err(25273): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err(25273): at java.lang.Thread.run(Thread.java:923) W/System.err(25273): Caused by: java.net.SocketException: Socket closed W/System.err(25273): at java.net.SocketInputStream.read(SocketInputStream.java:209) W/System.err(25273): at java.net.SocketInputStream.read(SocketInputStream.java:144) W/System.err(25273): at com.android.okhttp.okio.Okio$2.read(Okio.java:145) W/System.err(25273): at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:213) W/System.err(25273): ... 16 more
same for me (
same problem in 2022, any solution??
W/System.err(26991): java.net.SocketTimeoutException: timeout W/System.err(26991): at com.android.okhttp.okio.Okio$3.newTimeoutException(Okio.java:214) W/System.err(26991): at com.android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.java:263) W/System.err(26991): at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:217) W/System.err(26991): at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:51) W/System.err(26991): at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:395) W/System.err(26991): at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:372) W/System.err(26991): at java.io.InputStream.read(InputStream.java:101) W/System.err(26991): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:344) W/System.err(26991): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:201) eam.java:144) W/System.err(26991): at com.android.okhttp.okio.Okio$2.read(Okio.java:138) W/System.err(26991): ... 10 more
i used forked version of @valerybodak in my proyect, and have the same result. I modified the pubspec.yaml to implement:
flutter_downloader: git: https://github.com/valerybodak/flutter_downloader.git
is correct??
@alain8915 In my fork the timeout is set to 45 seconds, but looks like 45 seconds is not enough for you.