Skip to content

Commit a7729a5

Browse files
committed
fix(app, android): correct TaskExecutor shutdown error
Access to the collection of TaskExecutors wasn't correctly synchronized in all places Fixes #5225
1 parent 04d6bae commit a7729a5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/app/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
*
1818
*/
1919

20+
import java.util.ArrayList;
2021
import java.util.HashMap;
22+
import java.util.List;
2123
import java.util.Map;
22-
import java.util.Set;
2324
import java.util.concurrent.ExecutorService;
2425
import java.util.concurrent.Executors;
2526
import java.util.concurrent.RejectedExecutionHandler;
@@ -96,12 +97,14 @@ public String getExecutorName(boolean isTransactional, String identifier) {
9697
}
9798

9899
public void shutdown() {
99-
Set<String> existingExecutorNames = executors.keySet();
100-
for (String executorName : existingExecutorNames) {
101-
if (!executorName.startsWith(name)) {
102-
existingExecutorNames.remove(executorName);
103-
} else {
104-
removeExecutor(executorName);
100+
synchronized(executors) {
101+
List<String> existingExecutorNames = new ArrayList<>(executors.keySet());
102+
for (String executorName : existingExecutorNames) {
103+
if (!executorName.startsWith(name)) {
104+
executors.remove(executorName);
105+
} else {
106+
removeExecutor(executorName);
107+
}
105108
}
106109
}
107110
}

0 commit comments

Comments
 (0)