Immediately close server if no clients are connected

Summary: ^

Reviewed By: ivanmisuno

Differential Revision: D49539483

fbshipit-source-id: ffbcffe0f0b0f31bc26ba5881b30ae27960c283e
This commit is contained in:
Lorenzo Blasa
2023-09-22 10:31:15 -07:00
committed by Facebook GitHub Bot
parent 6251c58154
commit ddf348faa5

View File

@@ -39,7 +39,6 @@ const safe = (f: () => void) => {
}; };
let numberOfConnectedClients = 0; let numberOfConnectedClients = 0;
let disconnectTimeout: NodeJS.Timeout | undefined;
/** /**
* Attach and handle incoming messages from clients. * Attach and handle incoming messages from clients.
@@ -236,22 +235,14 @@ export function attachSocketServer(
server.offAny(onServerEvent); server.offAny(onServerEvent);
flipperServerCompanion?.destroyAll(); flipperServerCompanion?.destroyAll();
if (getFlipperServerConfig().environmentInfo.isHeadlessBuild) { if (
if (disconnectTimeout) { getFlipperServerConfig().environmentInfo.isHeadlessBuild &&
clearTimeout(disconnectTimeout); closeOnIdle
} ) {
if (closeOnIdle) {
/**
* If, after 60 seconds, there are no more connected clients, we exit the process.
*/
disconnectTimeout = setTimeout(() => {
if (numberOfConnectedClients === 0 && isProduction()) { if (numberOfConnectedClients === 0 && isProduction()) {
console.info('Shutdown as no clients are currently connected'); console.info('Shutdown as no clients are currently connected');
process.exit(0); process.exit(0);
} }
}, 60 * 1000);
}
} }
} }