lingochamp / FileDownloader

Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process
Apache License 2.0
10.98k stars 2.18k forks source link

java.net.ProtocolException: unexpected end of stream #1355

Open MirkoWu opened 3 years ago

MirkoWu commented 3 years ago

报错信息

java.net.ProtocolException: unexpected end of stream at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:398) at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:372) at java.io.InputStream.read(InputStream.java:101) at com.liulishuo.filedownloader.download.FetchDataTask.run(FetchDataTask.java:141) at com.liulishuo.filedownloader.download.DownloadRunnable.run(DownloadRunnable.java:121) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:929) version: 1.7.7

log

` I/FileDownloader.FileDownloadProperties: init properties 1 load properties: http.lenient=FALSE; process.non-separate=TRUE; download.min-progress-step=65536; download.min-progress-time=2000; download.max-network-thread-count=3; file.non-pre-allocation=FALSE; broadcast.completed=FALSE; download.trial-connection-head-method=FALSE D/FileDownloader.LostServiceConnectedHandler: Waiting for connecting with the downloader service... 902999258 D/FileDownloader.DownloadTaskHunter: free the task 902999258, when the status is 10 D/FileDownloader.FileDownloadDatabase: refreshed data count: 0 , delete data count: 0, reset id count: 0. consume 1 V/FileDownloader.FileDownloadEventPool: asyncPublishInNewThread event.service.connect.changed V/FileDownloader.FileDownloadEventPool: publish event.service.connect.changed D/FileDownloader.LostServiceConnectedHandler: The downloader service is connected. V/FileDownloader.DownloadTaskHunter: call start Url[https://static.quanminshike.com/apk/lqsw/releases/com.lqsw.duowanenvelope_base_2.1.7.apk], Path[/storage/emulated/0/lqsw/download/com.lqsw.duowanenvelope_base_2.1.7.apk] Listener[com.lqsw.duowanenvelope.view.dialog.UpdateDialogFragment$updateVersion$baseDownloadTask$1@5c8a4f0], Tag[null] V/FileDownloader.DownloadTaskHunter: the task[902999258] has been into the launch pool. D/FileDownloader.FileDownloadMessenger: notify begin 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 V/FileDownloader.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@7e39d9e by 11 V/FileDownloader.FileDownloadList: add list in all 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 11 1 D/FileDownloader.FileDownloadManager: request start the task with url(https://static.quanminshike.com/apk/lqsw/releases/com.lqsw.duowanenvelope_base_2.1.7.apk) path(/storage/emulated/0/lqsw/download/com.lqsw.duowanenvelope_base_2.1.7.apk) isDirectory(FALSE) D/FileDownloader.FileDownloadUtils: can't continue 902999258 file not suit, exists[FALSE], directory[FALSE] D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[11] new[1] 1 D/FileDownloader.FileDownloadMessenger: notify pending 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[1] new[6] 1 D/FileDownloader.FileDownloadMessenger: notify started 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 D/FileDownloader.MessageSnapshotGate: updateKeepFlow V/FileDownloader.ConnectTask: 902999258 add outside header: {Connection=[keep-alive]} D/FileDownloader.ConnectTask: <---- 902999258 request header {Connection=[keep-alive], Range=[bytes=0-0], User-Agent=[FileDownloader/1.7.7]} D/FileDownloader.ConnectTask: ----> 902999258 response header {null=[HTTP/1.1 206 Partial Content], Accept-Ranges=[bytes], Age=[0], Ali-Swift-Global-Savetime=[1596609907], Connection=[keep-alive], Content-Length=[1], Content-MD5=[dZXfX5kmZbGhkyaH96GZhw==], Content-Range=[bytes 0-0/18080792], Content-Type=[application/vnd.android.package-archive], Date=[Thu, 06 Aug 2020 09:44:28 GMT], EagleId=[7160b59e15967070687135380e], ETag=["7595DF5F992665B1A1932687F7A19987"], Last-Modified=[Wed, 05 Aug 2020 06:40:12 GMT], Server=[Tengine], Timing-Allow-Origin=[], Vary=[Origin], Via=[cache14.l2cn1823[25,304-0,H], cache16.l2cn1823[37,0], cache16.cn1368[143,206-0,H], cache10.cn1368[148,0]], X-Android-Received-Millis=[1596707065105], X-Android-Response-Source=[NETWORK 206], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1596707064942], X-Cache=[HIT TCP_REFRESH_HIT dirn:13:49229437], x-oss-cdn-auth=[success], x-oss-hash-crc64ecma=[7633098847487272055], x-oss-object-type=[Normal], x-oss-request-id=[5F2BD0FC5820623232C09082], x-oss-server-time=[7], x-oss-storage-class=[Standard], X-Swift-CacheTime=[3600], X-Swift-SaveTime=[Thu, 06 Aug 2020 09:44:28 GMT]} D/FileDownloader.FileDownloadUtils: etag find "7595DF5F992665B1A1932687F7A19987" for task(902999258) D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[6] new[2] 1 D/FileDownloader.FileDownloadMessenger: notify connected 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 D/FileDownloader.FileDownloadUtils: can't continue 902999258 file not suit, exists[FALSE], directory[FALSE] D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.DownloadLaunchRunnable: fetch data with multiple connection(count: [3]) for task[902999258] totalLength[18080792] D/FileDownloader.DownloadLaunchRunnable: enable multiple connection: id[902999258] index[0] range[0, 6026929) current offset(0) D/FileDownloader.DownloadLaunchRunnable: enable multiple connection: id[902999258] index[1] range[6026930, 12053859) current offset(6026930) D/FileDownloader.DownloadLaunchRunnable: enable multiple connection: id[902999258] index[2] range[12053860, -1) current offset(12053860) V/FileDownloader.ConnectTask: 902999258 add outside header: {Connection=[keep-alive]} D/FileDownloader.ConnectTask: <---- 902999258 request header {Connection=[keep-alive], Range=[bytes=0-6026929], User-Agent=[FileDownloader/1.7.7]} V/FileDownloader.ConnectTask: 902999258 add outside header: {Connection=[keep-alive]} D/FileDownloader.ConnectTask: <---- 902999258 request header {Connection=[keep-alive], Range=[bytes=12053860-], User-Agent=[FileDownloader/1.7.7]} V/FileDownloader.ConnectTask: 902999258 add outside header: {Connection=[keep-alive]} D/FileDownloader.ConnectTask: <---- 902999258 request header {Connection=[keep-alive], Range=[bytes=6026930-12053859], User-Agent=[FileDownloader/1.7.7]} D/FileDownloader.ConnectTask: ----> 902999258 response header {null=[HTTP/1.1 206 Partial Content], Accept-Ranges=[bytes], Age=[0], Ali-Swift-Global-Savetime=[1596609907], Connection=[keep-alive], Content-Length=[6026930], Content-MD5=[dZXfX5kmZbGhkyaH96GZhw==], Content-Range=[bytes 0-6026929/18080792], Content-Type=[application/vnd.android.package-archive], Date=[Thu, 06 Aug 2020 09:44:28 GMT], EagleId=[7160b59e15967070688826350e], ETag=["7595DF5F992665B1A1932687F7A19987"], Last-Modified=[Wed, 05 Aug 2020 06:40:12 GMT], Server=[Tengine], Timing-Allow-Origin=[], Vary=[Origin], Via=[cache14.l2cn1823[25,304-0,H], cache16.l2cn1823[37,0], cache16.cn1368[0,206-0,H], cache10.cn1368[2,0]], X-Android-Received-Millis=[1596707065133], X-Android-Response-Source=[NETWORK 206], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1596707065114], X-Cache=[HIT TCP_MEM_HIT dirn:13:49229437], x-oss-cdn-auth=[success], x-oss-hash-crc64ecma=[7633098847487272055], x-oss-object-type=[Normal], x-oss-request-id=[5F2BD0FC5820623232C09082], x-oss-server-time=[7], x-oss-storage-class=[Standard], X-Swift-CacheTime=[3600], X-Swift-SaveTime=[Thu, 06 Aug 2020 09:44:28 GMT]} D/FileDownloader.DownloadRunnable: the connection[0] for 902999258, is connected range[0, 6026929) current offset[0] with code[206] D/FileDownloader.FetchDataTask: start fetch(0): range [0, 6026929), seek to[0] I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress update model's status with progress I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[2] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 6105 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[0] offset[66857], consume[2] I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 193429 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 370508 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 550608 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.ConnectTask: ----> 902999258 response header {null=[HTTP/1.1 206 Partial Content], Accept-Ranges=[bytes], Age=[1], Ali-Swift-Global-Savetime=[1596609907], Connection=[keep-alive], Content-Length=[6026930], Content-MD5=[dZXfX5kmZbGhkyaH96GZhw==], Content-Range=[bytes 6026930-12053859/18080792], Content-Type=[application/vnd.android.package-archive], Date=[Thu, 06 Aug 2020 09:44:28 GMT], EagleId=[7160b5a115967070691813127e], ETag=["7595DF5F992665B1A1932687F7A19987"], Last-Modified=[Wed, 05 Aug 2020 06:40:12 GMT], Server=[Tengine], Timing-Allow-Origin=[], Vary=[Origin], Via=[cache14.l2cn1823[25,304-0,H], cache16.l2cn1823[37,0], cache16.cn1368[0,206-0,H], cache13.cn1368[2,0]], X-Android-Received-Millis=[1596707065448], X-Android-Response-Source=[NETWORK 206], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1596707065220], X-Cache=[HIT TCP_MEM_HIT dirn:13:49229437], x-oss-cdn-auth=[success], x-oss-hash-crc64ecma=[7633098847487272055], x-oss-object-type=[Normal], x-oss-request-id=[5F2BD0FC5820623232C09082], x-oss-server-time=[7], x-oss-storage-class=[Standard], X-Swift-CacheTime=[3600], X-Swift-SaveTime=[Thu, 06 Aug 2020 09:44:28 GMT]} D/FileDownloader.DownloadRunnable: the connection[1] for 902999258, is connected range[6026930, 12053859) current offset[6026930] with code[206] D/FileDownloader.FetchDataTask: start fetch(1): range [6026930, 12053859), seek to[6026930] D/FileDownloader.ConnectTask: ----> 902999258 response header {null=[HTTP/1.1 206 Partial Content], Accept-Ranges=[bytes], Age=[1], Ali-Swift-Global-Savetime=[1596609907], Connection=[keep-alive], Content-Length=[6026932], Content-MD5=[dZXfX5kmZbGhkyaH96GZhw==], Content-Range=[bytes 12053860-18080791/18080792], Content-Type=[application/vnd.android.package-archive], Date=[Thu, 06 Aug 2020 09:44:28 GMT], EagleId=[7160b59f15967070691852558e], ETag=["7595DF5F992665B1A1932687F7A19987"], Last-Modified=[Wed, 05 Aug 2020 06:40:12 GMT], Server=[Tengine], Timing-Allow-Origin=[], Vary=[Origin], Via=[cache14.l2cn1823[25,304-0,H], cache16.l2cn1823[37,0], cache16.cn1368[0,206-0,H], cache11.cn1368[1,0]], X-Android-Received-Millis=[1596707065449], X-Android-Response-Source=[NETWORK 206], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1596707065225], X-Cache=[HIT TCP_MEM_HIT dirn:13:49229437], x-oss-cdn-auth=[success], x-oss-hash-crc64ecma=[7633098847487272055], x-oss-object-type=[Normal], x-oss-request-id=[5F2BD0FC5820623232C09082], x-oss-server-time=[7], x-oss-storage-class=[Standard], X-Swift-CacheTime=[3600], X-Swift-SaveTime=[Thu, 06 Aug 2020 09:44:28 GMT]} D/FileDownloader.DownloadRunnable: the connection[2] for 902999258, is connected range[12053860, -1) current offset[12053860] with code[206] D/FileDownloader.FetchDataTask: start fetch(2): range [12053860, -1), seek to[12053860] D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[2] offset[12057956], consume[5] D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[1] offset[6031026], consume[2] I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 734096 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 1000336 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 1192848 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 1373072 18080792 . . 省略中间部分 . . D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 14966148 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[1] offset[12053860], consume[3] D/FileDownloader.DownloadLaunchRunnable: the connection has been completed(1): [6026930, 12053859) 18080792 D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[0] offset[3090128], consume[4] I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 15156278 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[0] offset[3159760], consume[4] I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[3] 1 D/FileDownloader.FileDownloadMessenger: notify progress 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 15336502 18080792 D/FileDownloader.MessageSnapshotGate: updateKeepFlow D/FileDownloader.FetchDataTask: require flushAndSync id[902999258] index[0] offset[3413712], consume[5] D/FileDownloader.DownloadLaunchRunnable: finish sub-task for [902999258] TRUE FALSE I/chatty: uid=10390(com.lqsw.duowanenvelope) FileDownloader- identical 1 line D/FileDownloader.DownloadLaunchRunnable: finish sub-task for [902999258] TRUE FALSE D/FileDownloader.MessageSnapshotGate: ~~~callback 902999258 old[3] new[-1] 1 V/FileDownloader.FileDownloadList: remove 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 left -1 0 D/FileDownloader.FileDownloadMessenger: notify error 902999258@com.liulishuo.filedownloader.DownloadTask@622dfd9 java.net.ProtocolException: unexpected end of stream V/FileDownloader.DownloadTaskHunter: filedownloader:lifecycle:over com.liulishuo.filedownloader.DownloadTaskHunter@7e39d9e by -1 D/FileDownloader.MessageSnapshotGate: updateKeepFlow W/FileDownloader.FileDownloader: request pause but not exist 902999258

` 不是必现,但在一台Android手机上复现几率达90%,基本都是一样的问题,下载一部分就不下载了,然后就任务失败了。别的手机暂时没发现这个问题。 看了很多人的帖子,什么添加Header都没有用,issues里感觉都没人解决这个问题,基本都是说服务端问题,文件是在阿里云上的,文件地址 ,求大佬帮忙看看,该怎么处理。

RocZhengPeng commented 3 years ago

我也遇到了

YuriTam commented 3 years ago

有没有人解决了这个问题的

jingzhanwu commented 3 years ago

最后怎么解决的

chailijun commented 3 years ago

碰到同样的问题,资源放在阿里云OSS上,浏览器下载正常,用该下载库下载基本100%复现该问题,求解??

javakam commented 3 years ago

应该是 okhttp 的问题 https://github.com/square/okhttp/issues/3715

javakam commented 3 years ago

我遇到的情况是Android模拟器无法访问到局域网域名问题, 需要给模拟器也设置hosts

https://juejin.cn/post/6966479937578467335

lixbandroid commented 3 years ago

现在是不维护了吗?为啥没有反馈啊?后台收到一大堆的崩溃日志

skyzhw commented 2 years ago

遇到同样问题,经过测试发现,在华为系列手机+阿里云CDN+特定的Wifi网络下,这个问题出现的概率很高。并且和当时的用网情况也有关系。根据排查,发现华为系手机socket的ReceiveBufferSize默认值是2097152,三星系统默认值是1048576.猜测和这个参数的系统调优有关。把华为系socket的ReceiveBufferSize参数调整到49152以下,这个问题出现概率很低,几乎很难复现。遇到同类问题的也可以试试.核心代码:new OkHttpClient.Builder().socketFactory(),socket.setReceiveBufferSize(49152);

v587jasonzou commented 10 months ago

同样的问题,我们通过抓包发现,我们的源文件设置了no-cache,阿里检测到文件大于100mb就会概率连接断开,出现response contnet-length和body大小不一的问题