Fix device cleanup
Summary: Fixes https://github.com/facebook/flipper/issues/1989 We had some self healing side effect that would destroy devices when registering a new device with the same serial, if they weren't yet. Redux isn't too happy about that, causing the attached crash. Instead introduced a utility to destroy devices, and log an error if the device life cycle isn't respected by the device implementations, rather than crashing we will now just waste some memory. Changelog: Fix a crash when disconnecting metro devices Reviewed By: passy Differential Revision: D26749214 fbshipit-source-id: 4c185ac521d44c1337fac8a9145440123b8b784c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4a71a5abd1
commit
224ec4d5d6
@@ -18,6 +18,7 @@ import {Payload, ConnectionStatus, ISubscriber} from 'rsocket-types';
|
||||
import {Flowable, Single} from 'rsocket-flowable';
|
||||
import Server from '../../server';
|
||||
import {buildClientId} from '../clientUtils';
|
||||
import {destroyDevice} from '../../reducers/connections';
|
||||
|
||||
const connections: Map<number, JSClientFlipperConnection<any>> = new Map();
|
||||
|
||||
@@ -83,12 +84,7 @@ export function initJsEmulatorIPC(
|
||||
if (payload.kind == 'ERROR' || payload.kind == 'CLOSED') {
|
||||
console.debug(`Device disconnected ${client.id}`, 'server');
|
||||
flipperServer.removeConnection(client.id);
|
||||
const toUnregister = new Set<string>();
|
||||
toUnregister.add(jsDeviceId(windowId));
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: toUnregister,
|
||||
});
|
||||
destroyDevice(store, logger, jsDeviceId(windowId));
|
||||
connections.delete(windowId);
|
||||
availablePlugins.delete(windowId);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import Server from '../../server';
|
||||
import {buildClientId} from '../clientUtils';
|
||||
import {selfInspectionClient} from './selfInspectionClient';
|
||||
import {flipperMessagesClientPlugin} from './plugins/FlipperMessagesClientPlugin';
|
||||
import {destroyDevice} from '../../reducers/connections';
|
||||
|
||||
export function initSelfInpector(
|
||||
store: Store,
|
||||
@@ -69,11 +70,7 @@ export function initSelfInpector(
|
||||
if (payload.kind == 'ERROR' || payload.kind == 'CLOSED') {
|
||||
console.debug(`Device disconnected ${client.id}`, 'server');
|
||||
flipperServer.removeConnection(client.id);
|
||||
const toUnregister = new Set<string>();
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: toUnregister,
|
||||
});
|
||||
destroyDevice(store, logger, client.id);
|
||||
}
|
||||
},
|
||||
onSubscribe(subscription) {
|
||||
|
||||
Reference in New Issue
Block a user