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
This commit is contained in:
committed by
Facebook Github Bot
parent
09c9aad32d
commit
26d58557ee
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user