mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix race condition that could cause downloader not to be canceled
PiperOrigin-RevId: 224048465
This commit is contained in:
parent
5bbe3ae7d6
commit
f8b85739b1
1 changed files with 3 additions and 7 deletions
|
|
@ -565,7 +565,7 @@ public final class DownloadManager {
|
||||||
*/
|
*/
|
||||||
@TargetState private volatile int targetState;
|
@TargetState private volatile int targetState;
|
||||||
|
|
||||||
@MonotonicNonNull private volatile Downloader downloader;
|
@MonotonicNonNull private Downloader downloader;
|
||||||
@MonotonicNonNull private Thread thread;
|
@MonotonicNonNull private Thread thread;
|
||||||
@MonotonicNonNull private Throwable error;
|
@MonotonicNonNull private Throwable error;
|
||||||
|
|
||||||
|
|
@ -624,6 +624,7 @@ public final class DownloadManager {
|
||||||
state = STATE_STARTED;
|
state = STATE_STARTED;
|
||||||
targetState = STATE_COMPLETED;
|
targetState = STATE_COMPLETED;
|
||||||
downloadManager.onTaskStateChange(this);
|
downloadManager.onTaskStateChange(this);
|
||||||
|
downloader = downloaderFactory.createDownloader(action);
|
||||||
thread = new Thread(this);
|
thread = new Thread(this);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
@ -648,11 +649,7 @@ public final class DownloadManager {
|
||||||
|
|
||||||
private void stopDownloadThread(@TargetState int targetState) {
|
private void stopDownloadThread(@TargetState int targetState) {
|
||||||
this.targetState = targetState;
|
this.targetState = targetState;
|
||||||
// TODO: The possibility of downloader being null here may prevent the download thread from
|
Assertions.checkNotNull(downloader).cancel();
|
||||||
// stopping in a timely way. Fix this.
|
|
||||||
if (downloader != null) {
|
|
||||||
downloader.cancel();
|
|
||||||
}
|
|
||||||
Assertions.checkNotNull(thread).interrupt();
|
Assertions.checkNotNull(thread).interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -675,7 +672,6 @@ public final class DownloadManager {
|
||||||
logd("Task is started", this);
|
logd("Task is started", this);
|
||||||
Throwable error = null;
|
Throwable error = null;
|
||||||
try {
|
try {
|
||||||
downloader = downloaderFactory.createDownloader(action);
|
|
||||||
if (action.isRemoveAction) {
|
if (action.isRemoveAction) {
|
||||||
downloader.remove();
|
downloader.remove();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue