Clean up socket on exit

Summary: Be more aggressive in cleaning up after ourselves. Using a tiny library by Sindre that handles standard exit events, SIGTERM and SIGINT.

Reviewed By: aigoncharov

Differential Revision: D35281772

fbshipit-source-id: a789f90f172b3aa3e187739cf2b7fefa75405891
This commit is contained in:
Pascal Hartig
2022-03-31 08:57:13 -07:00
committed by Facebook GitHub Bot
parent 42becc4b37
commit fd23a9d626
3 changed files with 14 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
"bugs": "https://github.com/facebook/flipper/issues",
"dependenciesComment": "mac-ca is required dynamically for darwin, node-fetch is treated special in electron-requires, not sure why",
"dependencies": {
"exit-hook": "^2.1.1",
"http-proxy": "^1.18.1",
"mac-ca": "^1.0.6",
"node-fetch": "^2.6.7",

View File

@@ -18,6 +18,7 @@ import {WEBSOCKET_MAX_MESSAGE_SIZE} from 'flipper-server-core';
import {parse} from 'url';
import xdgBasedir from 'xdg-basedir';
import proxy from 'http-proxy';
import exitHook from 'exit-hook';
import {userInfo} from 'os';
@@ -145,6 +146,13 @@ async function startProxyServer(
console.log('Starting socket server on ', socketPath);
console.log(`Starting proxy server on http://localhost:${config.port}`);
exitHook(() => {
console.log('Cleaning up socket on exit:', socketPath);
// This *must* run synchronously and we're not blocking any UI loop by definition.
// eslint-disable-next-line node/no-sync
fs.rmSync(socketPath, {force: true});
});
proxyServer.on('error', (err, _req, res) => {
console.warn('Error in proxy server:', err);
if (res instanceof ServerResponse) {

View File

@@ -5996,6 +5996,11 @@ execa@^4.0.0:
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"
exit-hook@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-2.2.1.tgz#007b2d92c6428eda2b76e7016a34351586934593"
integrity sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw==
exit-on-epipe@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz#0bdd92e87d5285d267daa8171d0eb06159689692"