Skip to content

Commit

Permalink
Exit if proxy fails
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lblasa authored and facebook-github-bot committed Jul 13, 2023
1 parent ca009d1 commit f404827
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions desktop/flipper-server-core/src/server/startServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit f404827

Please sign in to comment.