Skip to content

Commit

Permalink
fix(storage, android): fix concurrency issue (#10099)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Dec 15, 2022
1 parent 071c4d5 commit d0b6fcf
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private FlutterFirebaseStorageTask(
this.bytes = bytes;
this.fileUri = fileUri;
this.metadata = metadata;
inProgressTasks.put(handle, this);
synchronized (inProgressTasks) {
inProgressTasks.put(handle, this);
}
}

@Nullable
Expand All @@ -72,12 +74,7 @@ static void cancelInProgressTasks() {
synchronized (inProgressTasks) {
for (int i = 0; i < inProgressTasks.size(); i++) {
FlutterFirebaseStorageTask task = null;
try {
task = inProgressTasks.valueAt(i);
} catch (ArrayIndexOutOfBoundsException e) {
// TODO(Salakar): Why does this happen? Race condition / multiple destroy calls?
// Can safely ignore exception for now, see https://github.com/firebase/flutterfire/issues/4334
}
task = inProgressTasks.valueAt(i);
if (task != null) {
task.destroy();
}
Expand Down Expand Up @@ -150,12 +147,7 @@ void destroy() {
if (storageTask.isInProgress() || storageTask.isPaused()) {
storageTask.cancel();
}
try {
inProgressTasks.remove(handle);
} catch (ArrayIndexOutOfBoundsException e) {
// TODO(Salakar): Why does this happen? Race condition / multiple destroy calls?
// Can safely ignore exception for now, see https://github.com/firebase/flutterfire/issues/4334
}
inProgressTasks.remove(handle);
}

synchronized (cancelSyncObject) {
Expand Down

0 comments on commit d0b6fcf

Please sign in to comment.