From 26d58557ee82c78befe6111f3c4bb9c2a0724fb1 Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 9 Jul 2018 07:46:03 -0700 Subject: [PATCH] Android: Use separate thread for network connection Summary: We currently give sonar one event base from java / obj-c code to use for scheduling tasks. This causes a problem, because we schedule reconnect tasks on the event base, and then these tasks interact with rsocket which schedules it's own tasks. The problem is that we're passing rsocket the same event base. So the reconnect code executes and blocks waiting for rsocket to connect. But rsocket can never connect because it never executes because that thread is blocked, so we get deadlock. Fixing it by giving both processes their own event base / thread. Reviewed By: danielbuechele Differential Revision: D8748354 fbshipit-source-id: aa00766059f66fadfecb1970492bbb7107bbbfe4 --- android/android/AndroidSonarClient.java | 7 +++++-- android/android/SonarThread.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/android/android/AndroidSonarClient.java b/android/android/AndroidSonarClient.java index 40c9a7ed4..a648188b4 100644 --- a/android/android/AndroidSonarClient.java +++ b/android/android/AndroidSonarClient.java @@ -16,16 +16,19 @@ import com.facebook.sonar.core.SonarClient; public final class AndroidSonarClient { private static boolean sIsInitialized = false; private static SonarThread sSonarThread; + private static SonarThread sConnectionThread; public static synchronized SonarClient getInstance(Context context) { if (!sIsInitialized) { - sSonarThread = new SonarThread(); + sSonarThread = new SonarThread("SonarEventBaseThread"); sSonarThread.start(); + sConnectionThread = new SonarThread("SonarConnectionThread"); + sConnectionThread.start(); final Context app = context.getApplicationContext(); SonarClientImpl.init( sSonarThread.getEventBase(), - sSonarThread.getEventBase(), + sConnectionThread.getEventBase(), getServerHost(app), "Android", getFriendlyDeviceName(), diff --git a/android/android/SonarThread.java b/android/android/SonarThread.java index 608fb5a62..f3edeeb22 100644 --- a/android/android/SonarThread.java +++ b/android/android/SonarThread.java @@ -13,8 +13,8 @@ import javax.annotation.Nullable; class SonarThread extends Thread { private @Nullable EventBase mEventBase; - SonarThread() { - super("SonarEventBaseThread"); + SonarThread(final String name) { + super(name); } @Override