Fix timeout handlers being shared across connections
Summary: If multiple apps connect simultanously, they could overwrite or cancel each other timeoutHandles, leading to potential incorrect messages. Reviewed By: lblasa Differential Revision: D31015171 fbshipit-source-id: 1d498a90c8a7a1847d2a961fc944d2f74e734cc2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ebc905edd7
commit
e771394350
@@ -79,7 +79,7 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
|
|
||||||
flipperServer: FlipperServer;
|
flipperServer: FlipperServer;
|
||||||
|
|
||||||
timeHandler: NodeJS.Timeout | undefined;
|
timeHandlers: Map<string, NodeJS.Timeout> = new Map();
|
||||||
|
|
||||||
constructor(flipperServer: FlipperServer) {
|
constructor(flipperServer: FlipperServer) {
|
||||||
super();
|
super();
|
||||||
@@ -97,7 +97,6 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
this.altInsecureServer = null;
|
this.altInsecureServer = null;
|
||||||
this.browserServer = null;
|
this.browserServer = null;
|
||||||
this.initialized = null;
|
this.initialized = null;
|
||||||
this.timeHandler = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get logger(): Logger {
|
get logger(): Logger {
|
||||||
@@ -222,8 +221,8 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
this.logger.track('usage', 'trusted-request-handler-called', clientQuery);
|
this.logger.track('usage', 'trusted-request-handler-called', clientQuery);
|
||||||
this.connectionTracker.logConnectionAttempt(clientQuery);
|
this.connectionTracker.logConnectionAttempt(clientQuery);
|
||||||
|
|
||||||
if (this.timeHandler) {
|
if (this.timeHandlers.get(clientQueryToKey(clientQuery))) {
|
||||||
clearTimeout(this.timeHandler);
|
clearTimeout(this.timeHandlers.get(clientQueryToKey(clientQuery))!);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformedMedium = transformCertificateExchangeMediumToType(
|
const transformedMedium = transformCertificateExchangeMediumToType(
|
||||||
@@ -281,13 +280,16 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
// by client B. Client B timeHandler will override client A, thus, if
|
// by client B. Client B timeHandler will override client A, thus, if
|
||||||
// client A takes longer, then the unresponsive timeout will not be called
|
// client A takes longer, then the unresponsive timeout will not be called
|
||||||
// for it.
|
// for it.
|
||||||
this.timeHandler = setTimeout(() => {
|
this.timeHandlers.set(
|
||||||
this.emit('client-unresponsive-error', {
|
clientQueryToKey(clientQuery),
|
||||||
client,
|
setTimeout(() => {
|
||||||
medium,
|
this.emit('client-unresponsive-error', {
|
||||||
deviceID: response.deviceId,
|
client,
|
||||||
});
|
medium,
|
||||||
}, 30 * 1000);
|
deviceID: response.deviceId,
|
||||||
|
});
|
||||||
|
}, 30 * 1000),
|
||||||
|
);
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
@@ -532,3 +534,7 @@ async function findDeviceForConnection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default ServerController;
|
export default ServerController;
|
||||||
|
|
||||||
|
function clientQueryToKey(clientQuery: ClientQuery): string {
|
||||||
|
return `${clientQuery.app}/${clientQuery.os}/${clientQuery.device}/${clientQuery.device_id}`;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user