From f404827c696a30b6694b01a098218ade13b8cdf7 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Thu, 13 Jul 2023 03:59:58 -0700 Subject: [PATCH] Exit if proxy fails Summary: If the proxy fails, exit. The proxy server is the one listening on the supplied TCP port, used by PWA. If it has failed, then quit the process. Reviewed By: aigoncharov Differential Revision: D47433631 fbshipit-source-id: 55750db5bf3e00876074a6b403747ec07718878c --- .../flipper-server-core/src/server/startServer.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/desktop/flipper-server-core/src/server/startServer.tsx b/desktop/flipper-server-core/src/server/startServer.tsx index daf7ba8d7..95554ded0 100644 --- a/desktop/flipper-server-core/src/server/startServer.tsx +++ b/desktop/flipper-server-core/src/server/startServer.tsx @@ -206,13 +206,17 @@ async function startProxyServer( fs.rmSync(socketPath, {force: true}); }); - proxyServer?.on('error', (err, _req, res) => { + proxyServer?.on('error', (err, _req, _res) => { console.warn('Error in proxy server:', err); - if (res instanceof ServerResponse) { - res.writeHead(502, 'Failed to proxy request'); - } - res.end('Failed to proxy request: ' + err); tracker.track('server-proxy-error', {error: err.message}); + + // As it stands, if the proxy fails, which is the one + // listening on the supplied TCP port, then we should exit. + // Otherwise we risk staying in an invalid state, unable + // to recover, and thus preventing us to serve incoming requests. + // Bear in mind that exiting the process will trigger the exit hook + // defined above which will clean and close the sockets. + process.exit(0); }); return new Promise((resolve) => {