Simplify shutdown logic

Summary:
The previous logic aimed to reuse an existing server during bootstrap if the launched version was higher than the running one. This is no longer required or wanted.

## Risk assessment: LOW
### Rationale
It is extremely rare to launch Flipper whilst already having another instance running. This can happen during development, but it is extremely rare in production.

Launcher (singleton) launches Server (singleton).
Launcher can be executed multiple times and this will not create newer server instances.

If anything, if we are unable to kill any other instance, whatever that may be, continue. This is to cover the cases where a shutdown may have been acknowledged but the process is still shutting down.

Reviewed By: antonk52

Differential Revision: D51232901

fbshipit-source-id: 8b8b85f4bac68f5670b1878e827871f78dc68999
This commit is contained in:
Lorenzo Blasa
2023-11-13 12:51:45 -08:00
committed by Facebook GitHub Bot
parent 1199e1f667
commit bc77dcf326

View File

@@ -22,7 +22,6 @@ import {
UIPreference,
checkPortInUse,
checkServerRunning,
compareServerVersion,
getEnvironmentInfo,
openUI,
setupPrefetcher,
@@ -161,30 +160,24 @@ async function start() {
`[flipper-server][bootstrap] Keytar loaded (${keytarLoadedMS} ms)`,
);
let launchAndFinish = false;
console.info('[flipper-server] Check for running instances');
const existingRunningInstanceVersion = await checkServerRunning(argv.port);
if (existingRunningInstanceVersion) {
console.info(
`[flipper-server] Running instance found with version: ${existingRunningInstanceVersion}, current version: ${environmentInfo.appVersion}`,
);
if (
compareServerVersion(
environmentInfo.appVersion,
existingRunningInstanceVersion,
) > 0
) {
console.info(`[flipper-server] Shutdown running instance`);
await shutdownRunningInstance(argv.port);
} else {
launchAndFinish = true;
}
console.info(`[flipper-server] Shutdown running instance`);
const success = await shutdownRunningInstance(argv.port);
console.info(
`[flipper-server] Shutdown running instance acknowledged: ${success}`,
);
} else {
console.info('[flipper-server] Checking if port is in use (TCP)');
if (await checkPortInUse(argv.port)) {
console.info(`[flipper-server] Shutdown running instance`);
await shutdownRunningInstance(argv.port);
const success = await shutdownRunningInstance(argv.port);
console.info(
`[flipper-server] Shutdown running instance acknowledged: ${success}`,
);
}
}
@@ -194,10 +187,6 @@ async function start() {
`[flipper-server][bootstrap] Check for running instances completed (${runningInstanceShutdownMS} ms)`,
);
if (launchAndFinish) {
return await launch();
}
const {app, server, socket, readyForIncomingConnections} = await startServer(
{
staticPath,