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:
committed by
Facebook GitHub Bot
parent
42becc4b37
commit
fd23a9d626
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user