Filedownloader: 所有任务全部卡在 pending

Created on 7 Feb 2018  ·  14Comments  ·  Source: lingochamp/FileDownloader

当我下载文件时,有时会突然 不走progress, 这时如果 pause reuse start .. 有时会一直卡在 pending, 如果卡在pending的话, 这时候不论开启几个任务,全部都是卡在pending状态

need-info question

Most helpful comment

已经试过了你的 Demo ,目前发现的问题是,下载的过程中经常出现 ProtocolException: unexpected end of stream 这个错误。我用 Charles 抓包看了下连接,发现对于每一个连接,在 request 里面 range 指定需要下载的大小为 15M 左右,但实际上 response 的 body 里只接收到几百 K 连接就断掉了,这是问题所在。这个问题应该是发生在后端,为什么没有返回请求里指定多的数据就关掉了连接,造成 ProtocolException ?

当然也有可能是后端做了限制,即一个请求最多请求几百 K 的数据。基于这个假设,那么在断点下载的基础上,增加重试次数应该最终能下载完整个文件。为了验证,索性在你的 demo 里把重试次数改为 100 ,然后再试一下,发现果然可以正常下载完整个文件。

后来我把你 Demo 里第一个下载链接放在 Chrome 里进行下载,发现也是同样的情况,得重新加载好几次才能最终加载出整个文件。

All 14 comments

希望能提供 FileDownloader 的日志,这样能更清楚更快地解决问题。

.DownloadTaskHunter: call start Url[http://xxx/626166.pdf], Path[/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf] Listener[xxx.model.magazine.service.MagaDownloadService$2@1a866acc], Tag[null]
.DownloadTaskHunter: the task[-779291545] has been into the launch pool.
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by 11
.FileDownloadList: add list in all [email protected]@3e549c2a 11 1
.FileDownloadManager: request start the task with url(http://xxx/626166.pdf) path(/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf) isDirectory(FALSE)
.FileDownloadUtils: can't continue -779291545 file not suit, exists[FALSE], directory[FALSE]
.ConnectTask: <---- -779291545 request header {Range=[bytes=0-0], User-Agent=[FileDownloader/1.7.1]}
.MessageSnapshotGate: ~callback -779291545 old[11] new[1] 1
.FileDownloadMessenger: notify pending [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.MessageSnapshotGate: ~
callback -779291545 old[1] new[6] 1
.FileDownloadMessenger: notify started [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[1], Content-Range=[bytes 0-0/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:44 GMT], ETag=["5a79765d-2ca6bf8"], Last-Modified=[Tue, 06 Feb 20
.FileDownloadUtils: etag find "5a79765d-2ca6bf8" for task(-779291545)
.MessageSnapshotGate: ~callback -779291545 old[6] new[2] 1
.FileDownloadMessenger: notify connected [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.FileDownloadUtils: can't continue -779291545 file not suit, exists[FALSE], directory[FALSE]
.DownloadLaunchRunnable: fetch data with multiple connection(count: [3]) for task[-779291545] totalLength[46820344]
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[0] range[0, 15606780) current offset(0)
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[1] range[15606781, 31213561) current offset(15606781)
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[2] range[31213562, -1) current offset(31213562)
.ConnectTask: <---- -779291545 request header {Range=[bytes=0-15606780], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: <---- -779291545 request header {Range=[bytes=31213562-], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: <---- -779291545 request header {Range=[bytes=15606781-31213561], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[15606782], Content-Range=[bytes 31213562-46820343/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:44 GMT], ETag=["5a79765d-2ca6bf8"], Last-Mod
.DownloadRunnable: the connection[2] for -779291545, is connected range[31213562, -1) current offset[31213562] with code[206]
.FetchDataTask: start fetch(2): range [31213562, -1), seek to[31213562]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress update model's status with progress
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[2] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 1767 46820344
.MessageSnapshotGate: updateKeepFlow
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[15606781], Content-Range=[bytes 0-15606780/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:44 GMT], ETag=["5a79765d-2ca6bf8"], Last-Modified=[
.DownloadRunnable: the connection[0] for -779291545, is connected range[0, 15606780) current offset[0] with code[206]
.FetchDataTask: start fetch(0): range [0, 15606780), seek to[0]
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[31215329], consume[10]
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[15606781], Content-Range=[bytes 15606781-31213561/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:44 GMT], ETag=["5a79765d-2ca6bf8"], Last-Mod
.DownloadRunnable: the connection[1] for -779291545, is connected range[15606781, 31213561) current offset[15606781] with code[206]
.FetchDataTask: start fetch(1): range [15606781, 31213561), seek to[15606781]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[15607960], consume[8]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 492664 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: require flushAndSync id[-779291545] index[0] offset[66662], consume[30]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 941188 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 1410984 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 1879704 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: handleProgress notify user progress status
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 2351224 46820344
.MessageSnapshotGate: updateKeepFlow
.RemitDatabase: sync cache to db -779291545
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[32052781], consume[69]
.FetchDataTask: require flushAndSync id[-779291545] index[0] offset[850906], consume[32]
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[32095789], consume[12]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[16437240], consume[17]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[16437240], consume[8]
.DownloadLaunchRunnable: finish sub-task for [-779291545] TRUE FALSE
.DownloadLaunchRunnable: finish sub-task for [-779291545] TRUE FALSE
.DownloadLaunchRunnable: finish sub-task for [-779291545] TRUE FALSE
.MessageSnapshotGate: ~
callback -779291545 old[3] new[-1] 1
.FileDownloadList: remove [email protected]@3e549c2a left -1 0
.FileDownloadMessenger: notify error [email protected]@3e549c2a java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
.DownloadTaskHunter: filedownloader:lifecycle:over com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by -1
.MessageSnapshotGate: updateKeepFlow
.DownloadTaskHunter: High concurrent cause, Already is over, can't pause again, -1 -779291545
.DownloadTaskHunter: call start Url[http://xxx/626166.pdf], Path[/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf] Listenerxxx.model.magazine.service.MagaDownloadService$2@1a866acc], Tag[null]
.DownloadTaskHunter: the task[-779291545] has been into the launch pool.
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by 11
.FileDownloadList: add list in all [email protected]@3e549c2a 11 1
.FileDownloadManager: request start the task with url(http://xxx/626166.pdf) path(/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf) isDirectory(FALSE)
.MessageSnapshotGate: ~callback -779291545 old[11] new[1] 1
.FileDownloadMessenger: notify pending [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.MessageSnapshotGate: ~
callback -779291545 old[1] new[6] 1
.FileDownloadMessenger: notify started [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.ConnectTask: <---- -779291545 request header {If-Match=["5a79765d-2ca6bf8"], Range=[bytes=0-0], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[1], Content-Range=[bytes 0-0/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:48 GMT], ETag=["5a79765d-2ca6bf8"], Last-Modified=[Tue, 06 Feb 20
.FileDownloadUtils: etag find "5a79765d-2ca6bf8" for task(-779291545)
.MessageSnapshotGate: ~callback -779291545 old[6] new[2] 1
.FileDownloadMessenger: notify connected [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.DownloadLaunchRunnable: fetch data with multiple connection(count: [3]) for task[-779291545] totalLength[46820344]
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[0] range[0, 15606780) current offset(850906)
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[1] range[15606781, 31213561) current offset(16437240)
.DownloadLaunchRunnable: enable multiple connection: id[-779291545] index[2] range[31213562, -1) current offset(32095789)
.ConnectTask: <---- -779291545 request header {If-Match=["5a79765d-2ca6bf8"], Range=[bytes=32095789-], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: <---- -779291545 request header {If-Match=["5a79765d-2ca6bf8"], Range=[bytes=16437240-31213561], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: <---- -779291545 request header {If-Match=["5a79765d-2ca6bf8"], Range=[bytes=850906-15606780], User-Agent=[FileDownloader/1.7.1]}
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[14724555], Content-Range=[bytes 32095789-46820343/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:48 GMT], ETag=["5a79765d-2ca6bf8"], Last-Mod
.DownloadRunnable: the connection[2] for -779291545, is connected range[31213562, -1) current offset[32095789] with code[206]
.FetchDataTask: start fetch(2): range [31213562, -1), seek to[32095789]
.ConnectTask: ----> -779291545 response header {null=[HTTP/1.1 206 Partial Content], Connection=[close], Content-Length=[14776322], Content-Range=[bytes 16437240-31213561/46820344], Content-Type=[application/pdf], Date=[Wed, 07 Feb 2018 10:14:48 GMT], ETag=["5a79765d-2ca6bf8"], Last-Mod
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress update model's status with progress
.DownloadStatusCallback: handleProgress notify user progress status
.DownloadRunnable: the connection[1] for -779291545, is connected range[15606781, 31213561) current offset[16437240] with code[206]
.MessageSnapshotGate: ~
callback -779291545 old[2] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 2564771 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: start fetch(1): range [15606781, 31213561), seek to[16437240]
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[32096968], consume[8]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[16438419], consume[15]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 3036374 46820344
.MessageSnapshotGate: updateKeepFlow
.RemitDatabase: sync cache to db -779291545
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 3509110 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 3974766 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 4456690 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 4913934 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 5386670 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 5853038 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[33805168], consume[110]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[18372351], consume[17]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 6322770 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 6795570 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 7263702 46820344
.MessageSnapshotGate: updateKeepFlow
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 7263702 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[18974439], consume[133]
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[34319088], consume[140]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 7734350 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 8201854 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 8677690 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 9158478 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 9610470 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 10089654 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 10562086 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[21144587], consume[105]
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[35589288], consume[114]
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 11020830 46820344
.MessageSnapshotGate: updateKeepFlow
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 11020830 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.DownloadStatusCallback: handleProgress notify user progress status
.MessageSnapshotGate: ~callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 11490118 46820344
.MessageSnapshotGate: updateKeepFlow
.DownloadStatusCallback: handleProgress notify user progress status
.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
.MessageSnapshotGate: ~
callback -779291545 old[3] new[3] 1
.FileDownloadMessenger: notify progress [email protected]@3e549c2a 11961354 46820344
.MessageSnapshotGate: updateKeepFlow
.FetchDataTask: require flushAndSync id[-779291545] index[2] offset[36233148], consume[19]
.FetchDataTask: require flushAndSync id[-779291545] index[1] offset[22059419], consume[14]
.DownloadTaskHunter: the task[-779291545] has been expired from the launch pool.
.FileDownloadManager: request pause the task -779291545
.FileDownloadThreadPool: successful cancel -779291545 FALSE
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by -2
.FileDownloadList: remove [email protected]@3e549c2a left -2 0
.FileDownloadMessenger: notify paused [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:over com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by -2
.DownloadTaskHunter: call start Url[http://s.mrxinzhi.com//magazine/626166.pdf], Path[/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf] Listenerxxx.model.magazine.service.MagaDownloadService$2@1a866acc], Tag[null]
.DownloadTaskHunter: the task[-779291545] has been into the launch pool.
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by 11
.FileDownloadList: add list in all [email protected]@3e549c2a 11 1
.FileDownloadManager: request start the task with url(http://xxx/626166.pdf) path(/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf) isDirectory(FALSE)
.MessageSnapshotGate: ~callback -779291545 old[11] new[1] 1
.FileDownloadMessenger: notify pending [email protected]@3e549c2a
.MessageSnapshotGate: updateKeepFlow
.DownloadTaskHunter: the task[-779291545] has been expired from the launch pool.
.FileDownloadManager: request pause the task -779291545
.FileDownloadThreadPool: successful cancel -779291545 TRUE
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by -2
.FileDownloadList: remove [email protected]@3e549c2a left -2 0
.FileDownloadMessenger: notify paused [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:over com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by -2
.DownloadTaskHunter: call start Url[http://xxx/626166.pdf], Path[/storage/emulated/0/Android/dataxxxcache/magazine/pdf/626166.pdf] Listener[xxx.model.magazine.service.MagaDownloadService$2@1a866acc], Tag[null]
.DownloadTaskHunter: the task[-779291545] has been into the launch pool.
.FileDownloadMessenger: notify begin [email protected]@3e549c2a
.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@4177a1b by 11
.FileDownloadList: add list in all [email protected]@3e549c2a 11 1
.FileDownloadManager: request start the task with url(http:/xxx/626166.pdf) path(/storage/emulated/0/Android/data/xxx/cache/magazine/pdf/626166.pdf) isDirectory(FALSE)
.MessageSnapshotGate: ~
callback -779291545 old[11] new[1] 1

这时候又下载别的任务
DownloadTask: setPath /storage/emulated/0/Android/data/com.xxx.xxx/cache/magazine/pdf/626298.pdf
DownloadTask: setListener com.xxx.xxx.model.magazine.service.MagaDownloadService$2@c320c80
DownloadTaskHunter: call start Url[http://xxx/626298.pdf], Path[/storage/emulated/0/Android/data/com.xxx.xxx/cache/magazine/pdf/626298.pdf] Listener[com.xx.xxx.model.magazine.service.MagaDownloadService$2@c320c80], Tag[null]
DownloadTaskHunter: the task[1309789564] has been into the launch pool.
FileDownloadMessenger: notify begin [email protected]@18e836fe
DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@2214fe5f by 11
FileDownloadList: add list in all [email protected]@18e836fe 11 2
FileDownloadManager: request start the task with url(http://xxx/626298.pdf) path(/storage/emulated/0/Android/data/com.xx.xx/cache/magazine/pdf/626298.pdf) isDirectory(FALSE)
FileDownloadUtils: can't continue 1309789564 file not suit, exists[FALSE], directory[FALSE]
MessageSnapshotGate: ~~~callback 1309789564 old[11] new[1] 1
FileDownloadMessenger: notify pending [email protected]@18e836fe
MessageSnapshotGate: updateKeepFlow
一直停在这了, 并且也没有.temp文件创建, 跟了下代码,最后好像线程池里面的 run没有跑..不太确定.

通过分析你的日志,前面的下载一直是正常进行的,progress 也是一直在回调者,所以不清楚你说的突然不走 progress 回调是怎么回事?你想要的 progress 回调是怎样的?(比如频率)。


当 task 进入 pending 状态,下一步是进行一次很轻量的连接获取文件的大小。从你给的日志看,还没有连接结果返回,所以我推测是连接还未完成。完全卡主应该不会出现的,因为发生任何问题都会在 error 进行回调,内部不会有死循环的逻辑。而且在你第一段日志里,中间出现了 connect reset by peer 的错误,所以我怀疑后面你再重新开启任务建立连接的时候,也有可能有问题。关于 connect reset by peer 的问题,已经详细回答你了。综上,你再排除下连接的问题,比如你可以用 Charles/Wireshark 进行抓包,看看连接是否一直正常。

这个是我针对FileDownloadMessenger 进行的日志截取, 关掉过滤的话, 最后会有System.out Close OKHttp的 显示。然后就不在进行progress回调了,但是getStatus状态还是3。 这种情况下,我等了能有5 6分钟 都不动。 而且我下载别的任务 也全部卡在了pending,觉得这是不应该的。 我自己在看看,跟踪下日志吧。

那这种情况下你可对 FetchDataTask 的 run 方法进行断点,读取 stream 流的操作就在这里面,可以通过在这里断点判断下载任务是否还在继续。或者更直观一点用 Charles 抓包,可以持续观察 response 里 body 大小的变化。

开启所有任务都是pending状态, FetchDataTask 的 run方法没有跑。

@BinarySatan 可以提供你有问题的 Demo 的 Github 地址吗?然后我按照你目前提供的信息找下问题,在目前 FileDownloader 的 Demo 里面没有遇到过这种情况。

行,我弄个demo。

https://github.com/BinarySatan/FileDownDemo 你好这是项目地址,现在有的问题如下:
1,进度回滚
2,总是在66% 会卡.
3,只要一个任务一直pending,所有任务都会pending.

问题需要多测几次 就会出来。

好的,我会调试你的 Demo 看看具体问题。

谢谢。

已经试过了你的 Demo ,目前发现的问题是,下载的过程中经常出现 ProtocolException: unexpected end of stream 这个错误。我用 Charles 抓包看了下连接,发现对于每一个连接,在 request 里面 range 指定需要下载的大小为 15M 左右,但实际上 response 的 body 里只接收到几百 K 连接就断掉了,这是问题所在。这个问题应该是发生在后端,为什么没有返回请求里指定多的数据就关掉了连接,造成 ProtocolException ?

当然也有可能是后端做了限制,即一个请求最多请求几百 K 的数据。基于这个假设,那么在断点下载的基础上,增加重试次数应该最终能下载完整个文件。为了验证,索性在你的 demo 里把重试次数改为 100 ,然后再试一下,发现果然可以正常下载完整个文件。

后来我把你 Demo 里第一个下载链接放在 Chrome 里进行下载,发现也是同样的情况,得重新加载好几次才能最终加载出整个文件。

不过你所描述的突然不走 progress 的问题我依然没有在你的 Demo 里面复现

我这试了一下,应该不是后端做限制的问题,因为我这次可能下载停了,下次可能就不停,所以不确定是哪的问题 而且 就算改成100, 也会在某个点直接停下来不走了(需要手动pause 在 重新 createImpl .start,
而这步操作之后,可能继续下载,也有小概率一直pending,这时在开启别的任务也都是pending状态)
问题可能是基于后台断开链接才出现的吧,不太确定。

Was this page helpful?
0 / 5 - 0 ratings