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(app, android): fix TaskExecutor ConcurrentModificationException #5230

Merged
merged 4 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*
*/

import io.invertase.firebase.common.ReactNativeFirebaseJSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
Expand All @@ -36,7 +35,7 @@ public class TaskExecutorService {
private final String name;
private final int maximumPoolSize;
private final int keepAliveSeconds;
private static Map<String, ExecutorService> executors = new HashMap<>();
private static final Map<String, ExecutorService> executors = new HashMap<>();

TaskExecutorService(String name) {
this.name = name;
Expand Down Expand Up @@ -73,39 +72,39 @@ public ExecutorService getExecutor(boolean isTransactional, String identifier) {
}

private ExecutorService getNewExecutor(boolean isTransactional) {
if (isTransactional == true) {
if (isTransactional) {
return Executors.newSingleThreadExecutor();
} else {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<>());
threadPoolExecutor.setRejectedExecutionHandler(executeInFallback);
return threadPoolExecutor;
}
}

private RejectedExecutionHandler executeInFallback = new RejectedExecutionHandler() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
return;
}
ExecutorService fallbackExecutor = getTransactionalExecutor();
fallbackExecutor.execute(r);
};
private final RejectedExecutionHandler executeInFallback = (r, executor) -> {
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
return;
}
ExecutorService fallbackExecutor = getTransactionalExecutor();
fallbackExecutor.execute(r);
};

public String getExecutorName(boolean isTransactional, String identifier) {
if (isTransactional == true) {
if (isTransactional) {
return name + "TransactionalExecutor" + identifier;
}
return name + "Executor" + identifier;
}

public void shutdown() {
Set<String> existingExecutorNames = executors.keySet();
for (String executorName : existingExecutorNames) {
if (executorName.startsWith(name) == false) {
existingExecutorNames.remove(executorName);
} else {
removeExecutor(executorName);
synchronized(executors) {
List<String> existingExecutorNames = new ArrayList<>(executors.keySet());
for (String executorName : existingExecutorNames) {
if (!executorName.startsWith(name)) {
executors.remove(executorName);
} else {
removeExecutor(executorName);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/e2e/config.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('config', function () {
});

describe('json', function () {
xit('should read firebase.json data', async function () {
it('should read firebase.json data', async function () {
const jsonData = await NativeModules.RNFBAppModule.jsonGetAll();
jsonData.rnfirebase_json_testing_string.should.equal('abc');
jsonData.rnfirebase_json_testing_boolean_false.should.equal(false);
Expand Down
5 changes: 4 additions & 1 deletion tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ function Root() {
style={{ flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: 25, marginBottom: 30 }}>React Native Firebase</Text>
<Text style={{ fontSize: 25, marginBottom: 30 }}>End-to-End Testing App2</Text>
<Text style={{ fontSize: 25, marginBottom: 30 }}>End-to-End Testing App</Text>
<Button
style={{ flex: 1, marginTop: 20 }}
title={'Test Native Crash Now.'}
onPress={() => {
firebase.crashlytics().crash();
}}
/>
<View testId="spacer" style={{ height: 20 }} />
<Button
style={{ flex: 1, marginTop: 20 }}
title={'Test Javascript Crash Now.'}
onPress={() => {
undefinedVariable.notAFunction();
Expand Down