From 3999e9909a694dccd031ad17bcd9a26d24cc1d07 Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Fri, 5 Jun 2020 10:03:15 +0300 Subject: [PATCH] Close proxy server on app quit Signed-off-by: Lauri Nevala --- src/main/index.ts | 5 +++-- src/main/proxy.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 8bf99ca583..b1e43a4928 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -26,6 +26,7 @@ const promiseIpc = new PromiseIpc({ timeout: 2000 }) let windowManager: WindowManager = null; let clusterManager: ClusterManager = null; +let proxyServer: proxy.LensProxy = null; const vmURL = (isDevelopment) ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` : formatUrl({ pathname: path.join(__dirname, "index.html"), protocol: "file", @@ -57,10 +58,9 @@ async function main() { // create cluster manager clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port) - // run proxy try { - proxy.listen(port, clusterManager) + proxyServer = proxy.listen(port, clusterManager) } catch (error) { logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`) await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`) @@ -123,5 +123,6 @@ app.on("activate", () => { app.on("will-quit", async (event) => { event.preventDefault(); // To allow mixpanel sending to be executed if (clusterManager) clusterManager.stop() + if (proxyServer) proxyServer.close() app.exit(0); }) diff --git a/src/main/proxy.ts b/src/main/proxy.ts index 538a960702..bcfd432c9d 100644 --- a/src/main/proxy.ts +++ b/src/main/proxy.ts @@ -17,6 +17,7 @@ export class LensProxy { protected clusterManager: ClusterManager protected retryCounters: Map = new Map() protected router: Router + protected proxyServer: http.Server constructor(port: number, clusterManager: ClusterManager) { this.port = port @@ -27,6 +28,12 @@ export class LensProxy { public run() { const proxyServer = this.buildProxyServer(); proxyServer.listen(this.port, "127.0.0.1") + this.proxyServer = proxyServer + } + + public close() { + logger.info("Closing proxy server") + this.proxyServer.close() } protected buildProxyServer() {