From bc77dcf3266c822572bcfa11dfd73ed27d00fd60 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 13 Nov 2023 12:51:45 -0800 Subject: [PATCH] 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 --- desktop/flipper-server/src/index.tsx | 29 +++++++++------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/desktop/flipper-server/src/index.tsx b/desktop/flipper-server/src/index.tsx index 5ab044506..36837a0a9 100644 --- a/desktop/flipper-server/src/index.tsx +++ b/desktop/flipper-server/src/index.tsx @@ -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,