lingochamp / okdownload

A Reliable, Flexible, Fast and Powerful download engine.
Apache License 2.0
5.19k stars 776 forks source link

在android10下有下载进度更新错误导致下载暂停的问题 #378

Open fenghebaiyang opened 4 years ago

fenghebaiyang commented 4 years ago

OkDownload Version

v1.0.7-SNAPSHOT

Problem Describe

在Android10下下载经常在回调中收到 The current offset on block-info isn't update correct, 58170771 != 226488053 on 0 这种错误 在android10之前的版本是没有 设备是小米8 MIUI 11 Android10

Log

14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: task[7] current need fetching block count 2 is not equal to no more stream block count 0 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream sync success (7) block(0) syncLength(1212416) currentOffset(446201235) 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream sync success (7) block(1) syncLength(20525056) currentOffset(561102233) 14:56:35D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:35D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:35D/MultiPointOutputStream [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: task[7] current need fetching block count 2 is not equal to no more stream block count 1 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: task[7] current need fetching block count 2 is not equal to no more stream block count 1 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: runSync state change isNoMoreStream[false] newNoMoreStreamBlockList[[1]] 14:56:35D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:35D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream sync success (7) block(0) syncLength(491520) currentOffset(446692755) 14:56:35D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream sync success (7) block(1) syncLength(5117895) currentOffset(566220128) 14:56:35D/MultiPointOutputStream [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream close task[7] block[1] 14:56:37D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:37D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:37D/MultiPointOutputStream [OkDownload file io, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: task[7] current need fetching block count 2 is not equal to no more stream block count 1 14:56:39D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:39D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:41D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:41D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:43D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:43D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:45D/CallbackDispatcher [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: fetchEnd: 7 14:56:45D/DownloadChain [OkDownload Cancel Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: release connection com.liulishuo.okdownload.core.connection.DownloadOkHttp3Connection@f20abeb task[7] block[1] 14:56:45D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:45D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:47D/MultiPointOutputStream [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream done but no need to ensure sync, because the syncFuture.isDone[true] task[7] block[0] 14:56:47D/MultiPointOutputStream [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: OutputStream close task[7] block[0] 14:56:47D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isPending: 7 14:56:47D/DownloadDispatcher [main, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: isRunning: 7 14:56:55D/DownloadCache [OkDownload Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: catch unknown error java.io.IOException: The current offset on block-info isn't update correct, 446692755 != 566220129 on 0 14:56:55D/DownloadChain [OkDownload Cancel Block, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: release connection com.liulishuo.okdownload.core.connection.DownloadOkHttp3Connection@6942d60 task[7] block[0] 14:56:55D/CallbackDispatcher [download call: 7, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: taskEnd: 7 ERROR java.io.IOException: The current offset on block-info isn't update correct, 446692755 != 566220129 on 0 14:56:55D/RemitSyncExecutor [OkDownload RemitHandoverToDB, com.mvmtv.player.download.VideoDownManager$1.d(VideoDownManager.java:133)]: remove free bunch id 7 14:56:55I/taskEnd [download call: 7, com.mvmtv.player.download.VideoDownManager$2.taskEnd(VideoDownManager.java:187)]: https://movie-1255625324.file.myqcloud.com/2019-08-05_fdryks7437.mp4?sign=1584341693-yNsncS-0-e361f3cba9ee8ff818bcefd71c9a085d ---------------------------EndCause:ERROR-----------Exception:java.io.IOException: The current offset on block-info isn't update correct, 446692755 != 566220129 on 0

fenghebaiyang commented 4 years ago

尝试去修复了一下,强制将连接设置成了2个后,发现在一个block先下载完成后,另外一个block下载完成调用MultiPointOutputStream的done方法时,syncFuture.isDone == true ,但这时noSyncLengthMap中对应的未更新的进度并没有累加到block-info的currentOffset,然后在inspectComplete中判断的时候抛出了异常

zhouzhuyuan commented 4 years ago

更具体原因是因为MultiPointOutputStream中的flushProcess中的size和outputStreamMap的size没有对应,导致下标越界了,你把IOException改为Exception可已捕获这个异常,同时由于是在独立的线程池中进行的,所以异常没有继续向外抛。

zhouzhuyuan commented 4 years ago

问题解决了,Android 10 修改了SparseArray,在Android 9 和之前的版本,传入的下标越界不做处理,现在会抛异常了。!!!!!

zzg1122 commented 4 years ago

问题解决了,Android 10 修改了SparseArray,在Android 9 和之前的版本,传入的下标越界不做处理,现在会抛异常了。!!!!!

请问具体解决办法能发出来吗?谢谢啦

zhouzhuyuan commented 4 years ago

问题解决了,Android 10 修改了SparseArray,在Android 9 和之前的版本,传入的下标越界不做处理,现在会抛异常了。!!!!!

请问具体解决办法能发出来吗?谢谢啦

你去保证MultiPointOutputStream中的outputStreamMap和noSyncLengthMap长度一致即可,源码中在outputStreamMap移除的时候没有更新noSyncLengthMap的长度。可能还是不最优解法,但目前我是这么搞得。>.<

owenxiao-AS commented 4 years ago

问题解决了,Android 10 修改了SparseArray,在Android 9 和之前的版本,传入的下标越界不做处理,现在会抛异常了。!!!!!

请问具体解决办法能发出来吗?谢谢啦

你去保证MultiPointOutputStream中的outputStreamMap和noSyncLengthMap长度一致即可,源码中在outputStreamMap移除的时候没有更新noSyncLengthMap的长度。可能还是不最优解法,但目前我是这么搞得。>.<

我在close方法中判断是否是android10 然后进行 noSyncLengthMap.remove(blockIndex); 不会炸了 但是暂停了 再次进行下载 是从头开始了 而不是接着下载 你遇到过吗 就android10这样