Skip to content

Timeout when blocking tasks on any thread. #3645

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

Merged
merged 1 commit into from
Apr 13, 2022
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 @@ -49,6 +49,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;

class CrashlyticsController {
Expand Down Expand Up @@ -241,6 +242,8 @@ public Task<Void> then(@Nullable Settings settings) throws Exception {
try {
// TODO(mrober): Don't block the main thread ever for on-demand fatals.
Utils.awaitEvenIfOnMainThread(handleUncaughtExceptionTask);
} catch (TimeoutException e) {
Logger.getLogger().e("Cannot send reports. Timed out while fetching settings.");
} catch (Exception e) {
Logger.getLogger().e("Error handling uncaught exception", e);
// Nothing to do in this case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static java.util.Objects.requireNonNull;

import android.os.Looper;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -122,11 +121,7 @@ public static <T> T awaitEvenIfOnMainThread(Task<T> task)
return null;
});

if (Looper.getMainLooper() == Looper.myLooper()) {
latch.await(CrashlyticsCore.DEFAULT_MAIN_HANDLER_TIMEOUT_SEC, TimeUnit.SECONDS);
} else {
latch.await();
}
latch.await(CrashlyticsCore.DEFAULT_MAIN_HANDLER_TIMEOUT_SEC, TimeUnit.SECONDS);

if (task.isSuccessful()) {
return task.getResult();
Expand Down