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
@@ -20,6 +20,7 @@ import {promisify} from 'util';
|
||||
import {ServerPorts} from '../reducers/application';
|
||||
import {Client as ADBClient} from 'adbkit';
|
||||
import {addErrorNotification} from '../reducers/notifications';
|
||||
import {destroyDevice} from '../reducers/connections';
|
||||
|
||||
function createDevice(
|
||||
adbClient: ADBClient,
|
||||
@@ -235,9 +236,8 @@ export default (store: Store, logger: Logger) => {
|
||||
)
|
||||
.map((device) => device.serial);
|
||||
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: new Set(reconnectedDevices),
|
||||
reconnectedDevices.forEach((serial) => {
|
||||
destroyDevice(store, logger, serial);
|
||||
});
|
||||
|
||||
androidDevice.loadDevicePlugins(
|
||||
|
||||
@@ -21,6 +21,7 @@ import IOSDevice from '../devices/IOSDevice';
|
||||
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice';
|
||||
import {addErrorNotification} from '../reducers/notifications';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
import {destroyDevice} from '../reducers/connections';
|
||||
|
||||
type iOSSimulatorDevice = {
|
||||
state: 'Booted' | 'Shutdown' | 'Shutting Down';
|
||||
@@ -127,6 +128,8 @@ function processDevices(
|
||||
if (currentDeviceIDs.has(udid)) {
|
||||
currentDeviceIDs.delete(udid);
|
||||
} else {
|
||||
// clean up offline device
|
||||
destroyDevice(store, logger, udid);
|
||||
logger.track('usage', 'register-device', {
|
||||
os: 'iOS',
|
||||
type: type,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice';
|
||||
import MetroDevice from '../devices/MetroDevice';
|
||||
import http from 'http';
|
||||
import {addErrorNotification} from '../reducers/notifications';
|
||||
import {destroyDevice} from '../reducers/connections';
|
||||
|
||||
const METRO_PORT = 8081;
|
||||
const METRO_HOST = 'localhost';
|
||||
@@ -75,18 +76,6 @@ export async function registerMetroDevice(
|
||||
);
|
||||
}
|
||||
|
||||
async function unregisterDevices(store: Store, logger: Logger) {
|
||||
logger.track('usage', 'unregister-device', {
|
||||
os: 'Metro',
|
||||
serial: METRO_URL,
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: new Set([METRO_URL]),
|
||||
});
|
||||
}
|
||||
|
||||
export default (store: Store, logger: Logger) => {
|
||||
let timeoutHandle: NodeJS.Timeout;
|
||||
let ws: WebSocket | undefined;
|
||||
@@ -111,7 +100,7 @@ export default (store: Store, logger: Logger) => {
|
||||
unregistered = true;
|
||||
clearTimeout(guard);
|
||||
ws = undefined;
|
||||
unregisterDevices(store, logger);
|
||||
destroyDevice(store, logger, METRO_URL);
|
||||
scheduleNext();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user