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

fix ProgressiveDownloader infinite loop #10570

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -88,19 +88,7 @@ public ProgressiveDownloader(
public void download(@Nullable ProgressListener progressListener)
throws IOException, InterruptedException {
this.progressListener = progressListener;
downloadRunnable =
new RunnableFutureTask<Void, IOException>() {
@Override
protected Void doWork() throws IOException {
cacheWriter.cache();
return null;
}

@Override
protected void cancelWork() {
cacheWriter.cancel();
}
};
downloadRunnable = createDownloadTask();

if (priorityTaskManager != null) {
priorityTaskManager.add(C.PRIORITY_DOWNLOAD);
Expand All @@ -119,6 +107,8 @@ protected void cancelWork() {
Throwable cause = Assertions.checkNotNull(e.getCause());
if (cause instanceof PriorityTooLowException) {
// The next loop iteration will block until the task is able to proceed.
// recreate downloadRunnable in order to prevent error state caching
downloadRunnable = createDownloadTask();
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
Expand Down Expand Up @@ -161,4 +151,19 @@ private void onProgress(long contentLength, long bytesCached, long newBytesCache
: ((bytesCached * 100f) / contentLength);
progressListener.onProgress(contentLength, bytesCached, percentDownloaded);
}

private RunnableFutureTask<Void, IOException> createDownloadTask() {
return new RunnableFutureTask<Void, IOException>() {
@Override
protected Void doWork() throws IOException {
cacheWriter.cache();
return null;
}

@Override
protected void cancelWork() {
cacheWriter.cancel();
}
};
}
}