From 9d41c3c44c882b470c9809a774f0fb33d3f1b2bd Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 4 Nov 2021 09:11:50 -0700 Subject: [PATCH] Fix device connection timeout notification Summary: Currently, when a new app connects to Flipper, we show a lost connection notification even though it successfully connects to Flipper. It happens because we of the device_id mismatch. Reviewed By: mweststrate Differential Revision: D32169917 fbshipit-source-id: 6df3ae7fd621b4549e18c1835473a13f18cfb339 --- .../src/comms/ServerController.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/desktop/flipper-server-core/src/comms/ServerController.tsx b/desktop/flipper-server-core/src/comms/ServerController.tsx index 322ddf739..4d1578233 100644 --- a/desktop/flipper-server-core/src/comms/ServerController.tsx +++ b/desktop/flipper-server-core/src/comms/ServerController.tsx @@ -294,14 +294,14 @@ class ServerController extends EventEmitter implements ServerEventsListener { deviceName: clientQuery.device, appName: appNameWithUpdateHint(clientQuery), }; - // TODO: if multiple clients are establishing a connection - // at the same time, then this unresponsive timeout can potentially - // lead to errors. For example, client A starts connectiving followed - // by client B. Client B timeHandler will override client A, thus, if - // client A takes longer, then the unresponsive timeout will not be called - // for it. + this.timeHandlers.set( - clientQueryToKey(clientQuery), + // In the original insecure connection request, `device_id` is set to "unknown". + // Flipper queries adb/idb to learn the device ID and provides it back to the app. + // Once app knows it, it starts using the correct device ID for its subsequent secure connections. + // When the app re-connects securely after the cert exchange process, we need to cancel this timeout. + // Since the original clientQuery has `device_id` set to "unknown", we update it here with the correct `device_id` to find it and cancel it later. + clientQueryToKey({...clientQuery, device_id: response.deviceId}), setTimeout(() => { this.emit('client-unresponsive-error', { client,