Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseDownloadTask#reuse is called shortly after the call to BaseDownloadTask#pause may raise a exception #329

Closed
liangnansheng opened this issue Sep 26, 2016 · 19 comments

Comments

@liangnansheng
Copy link

java.lang.IllegalStateException: the messenger is working, can't re-appointment for [email protected]@42a72b80

@Jacksgong
Copy link
Collaborator

你是在哪里调用遇到这个问题的呢?

@liangnansheng
Copy link
Author

task.reuse();

@liangnansheng
Copy link
Author

场景就是网络不好的时候,不断点击下载就会出现~

@Jacksgong
Copy link
Collaborator

在哪里调用task.reuse();。是回调里吗?

@liangnansheng
Copy link
Author

没有出现在回调里

@Jacksgong
Copy link
Collaborator

Jacksgong commented Sep 26, 2016

task.reuse()方法你是在哪里调用的。

这个错误,说明当前任务还在不断的接收回调,无法重新reuse

之前有一个版本有修复一个类似的问题(#229),他这个是在 completed/paused/warn/error 这些回调中调用了trask.reuse()导致报了上面的错误,后来在0.3.4中修复了。

@liangnansheng
Copy link
Author

我给他加了一个判断就是if(task.isusing){};后解决了

@Jacksgong
Copy link
Collaborator

恩。好的。如果觉得报这个异常是不符合预期的,继续评论,我会重新打开这个issue,然后继续跟踪问题。

@vinaaroncent
Copy link

我出现同样的问题
if (task.getStatus(task.getId(), task.getTargetFilePath()) == FileDownloadStatus.paused) {
mAExtendPackage.baseDownloadTask.reuse();
mAExtendPackage.baseDownloadTask.start();
}

@vinaaroncent
Copy link

写错了。。sorry
if (task.getStatus(task.getId(), task.getTargetFilePath()) == FileDownloadStatus.paused) {
task.reuse();
task.start();
}
然后就在task reuse 那里报错了 之前我程序把task pause了

@Jacksgong
Copy link
Collaborator

@vinaaroncent 可否告知下遇到该问题的FileDownloader的版本。

@vinaaroncent
Copy link

1.2.2

@Jacksgong
Copy link
Collaborator

@vinaaroncent 可否告知下task是什么类的对象。因为如果是BaseDownloadTask是没有task.getStatus(task.getId(), task.getTargetFilePath())这样的接口的。只有可能是: task.getStatus()


类似问题我重新review了一遍代码,当然你也可以看下报错的源代码。有有可能在任务还在运行之时,进行调用它的BaseDownloadTask#reuse才有可能出现对应的异常。

@vinaaroncent
Copy link

sorry~ 我手敲的代码 不是复制的 弄错了。
之前的 getStatus 是 FileDownloader.getImpl().getStatus
task 是BaseDownloadTask

@vinaaroncent
Copy link

必复现的流程是:
我在上一个activty的onpause里把task pause了
然后进入下一个activty 在oncreate里判断task是否pause,如果pause 我就reuse start

@Jacksgong
Copy link
Collaborator

@vinaaroncent 挺奇怪的,FileDownloader并没有与Activity有任何的绑定关系。。可否加下QQ,我给你远程看下吧。我QQ 82780465。加好了回来评论下,我比较少上QQ,然后约定时间。我给你远程定位下问题。

@vinaaroncent
Copy link

已加~

@Jacksgong Jacksgong added the bug label Oct 24, 2016
@Jacksgong Jacksgong added this to the 1.3.0 milestone Oct 24, 2016
@Jacksgong
Copy link
Collaborator

@vinaaroncent 多谢提供的sample project,已经找到原因。

这个问题会在3.0中修复了带上。

原因:

调用BaseDownloadTask#pause的时候,并没有同步的进行释放BaseDownloadTask的Messenger,因为还有至少一个pause的消息需要通过Messager回调给BaseDownloadListener,而默认情况下这个回调并不是同步的,而是放到回调队列中,在排到的时候才抛回主线程的Looper中进行回调。

因此在调用BaseDownloadTask#pause之后,立马或者短时间内直接调用BaseDownloadTask#reuse,就可能遇到上面的问题。


Resaon

Calling BaseDownloadTask#pause doesn't release the Messenger for the BaseDownloadTask object synchronously, since there is at least one pause message needs to be called back to the BaseDownloadListener via the Messager, and by default, this callback is not synchronized, what is placed in the callback queue waiting for callback in the looper of the main thread.

So in the call BaseDownloadTask#pause after called BaseDownloadTask#reuse in a short period of time, may raised this exception.

@Jacksgong Jacksgong changed the title 请问这个问题~如何解决是好~ call BaseDownloadTask#pause after called BaseDownloadTask#reuse in a short period of time, may raise a exception Oct 24, 2016
@Jacksgong Jacksgong changed the title call BaseDownloadTask#pause after called BaseDownloadTask#reuse in a short period of time, may raise a exception BaseDownloadTask#reuse is called shortly after the call to BaseDownloadTask#pause may raise a exception Oct 31, 2016
@B-Esmaili
Copy link

would you mind using english?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants