Set unresponsive timeout
Summary: Set a timeout period to become ready. It is better to kill the server if not ready, than keeping it alive. Reviewed By: antonk52 Differential Revision: D50004605 fbshipit-source-id: be1d2c022c634ece059fc03eb6faea695431ba95
This commit is contained in:
committed by
Facebook GitHub Bot
parent
541570c8ab
commit
e8aad89b0b
@@ -20,7 +20,7 @@ import {FlipperServerImpl} from '../FlipperServerImpl';
|
||||
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
|
||||
import {validateAuthToken} from '../app-connectivity/certificate-exchange/certificate-utils';
|
||||
import {tracker} from '../tracker';
|
||||
import {EnvironmentInfo} from 'flipper-common';
|
||||
import {EnvironmentInfo, isProduction} from 'flipper-common';
|
||||
|
||||
type Config = {
|
||||
port: number;
|
||||
@@ -85,6 +85,13 @@ const verifyAuthToken = (req: http.IncomingMessage): boolean => {
|
||||
let isReady = false;
|
||||
let isReadyWaitable: Promise<void> | undefined;
|
||||
|
||||
/**
|
||||
* Time to wait until server becomes ready to accept incoming connections.
|
||||
* If within 30 seconds it is not ready, the server is considered unresponsive
|
||||
* and must be terminated.
|
||||
*/
|
||||
const timeoutSeconds = 30;
|
||||
|
||||
/**
|
||||
* Orchestrates the creation of the HTTP server, proxy, and WS server.
|
||||
* @param config Server configuration.
|
||||
@@ -99,6 +106,15 @@ export async function startServer(
|
||||
socket: WebSocketServer;
|
||||
readyForIncomingConnections: ReadyForConnections;
|
||||
}> {
|
||||
setTimeout(() => {
|
||||
if (!isReady && isProduction()) {
|
||||
console.error(
|
||||
`[flipper-server] Unable to become ready within ${timeoutSeconds} seconds, exit`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}, timeoutSeconds * 1000);
|
||||
|
||||
return await startHTTPServer(config, environmentInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user