Skip to content

Commit

Permalink
Reintroduce timeout and is production check
Browse files Browse the repository at this point in the history
Summary:
For dev, let's not kill the server.
Also, reintroduce a timeout of 60 seconds before disconnecting.

Reviewed By: antonk52

Differential Revision: D48432317

fbshipit-source-id: bac6f67101e5be481af06a5ea6ccb3b3134c4075
  • Loading branch information
lblasa authored and facebook-github-bot committed Aug 17, 2023
1 parent ce13ee4 commit 3f37d29
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions desktop/flipper-server-core/src/server/attachSocketServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SystemError,
getLogger,
CompanionEventWebSocketMessage,
isProduction,
} from 'flipper-common';
import {FlipperServerImpl} from '../FlipperServerImpl';
import {RawData, WebSocketServer} from 'ws';
Expand All @@ -38,6 +39,7 @@ const safe = (f: () => void) => {
};

let numberOfConnectedClients = 0;
let disconnectTimeout: NodeJS.Timeout | undefined;

/**
* Attach and handle incoming messages from clients.
Expand Down Expand Up @@ -239,10 +241,19 @@ export function attachSocketServer(
flipperServerCompanion?.destroyAll();

if (getFlipperServerConfig().environmentInfo.isHeadlessBuild) {
if (numberOfConnectedClients === 0) {
console.info('Shutdown as no clients are currently connected');
process.exit(0);
if (disconnectTimeout) {
clearTimeout(disconnectTimeout);
}

/**
* If, after 60 seconds, there are no more connected clients, we exit the process.
*/
disconnectTimeout = setTimeout(() => {
if (numberOfConnectedClients === 0 && isProduction()) {
console.info('Shutdown as no clients are currently connected');
process.exit(0);
}
}, 60 * 1000);
}
}

Expand Down

0 comments on commit 3f37d29

Please sign in to comment.