From f8443f8960d706a2afd8b34714a8a0d4c8b474b5 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 8 May 2019 17:42:40 +0300 Subject: [PATCH] fix: ensure analytics and cleanup processes are not leaking When CLI dies, the `analyticsBroker` and `cleanupProcess` processes receive disconnect event. At this point they have to finish their work and die silently after that. However, this does not happen for `analyticsBroker` process as in the `disconnect` handler we call `process.disconnect` method. It fails, as the process is already disconnected. So the process hangs in undefined state and it leaks. The stareted cleanup process from it also leaks. To fix this remove the disconnect call from the handler. Also ensure injector is disposed before calling process.exit in the detached process's handler. --- lib/detached-processes/cleanup-process.ts | 2 ++ lib/services/analytics/analytics-broker-process.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/detached-processes/cleanup-process.ts b/lib/detached-processes/cleanup-process.ts index 825b48d613..a6bd0c7975 100644 --- a/lib/detached-processes/cleanup-process.ts +++ b/lib/detached-processes/cleanup-process.ts @@ -166,6 +166,8 @@ process.on("message", async (cleanupProcessMessage: ICleanupMessageBase) => { process.on("disconnect", async () => { fileLogService.logData({ message: "cleanup-process received process.disconnect event" }); await executeCleanup(); + $injector.dispose(); + process.exit(); }); fileLogService.logData({ message: `cleanup-process will send ${DetachedProcessMessages.ProcessReadyToReceive} message` }); diff --git a/lib/services/analytics/analytics-broker-process.ts b/lib/services/analytics/analytics-broker-process.ts index 9fee55b3a5..5e7439af26 100644 --- a/lib/services/analytics/analytics-broker-process.ts +++ b/lib/services/analytics/analytics-broker-process.ts @@ -29,7 +29,7 @@ const finishTracking = async (data?: ITrackingInformation) => { analyticsLoggingService.logData({ message: `analytics-broker-process finish tracking started` }); await trackingQueue; analyticsLoggingService.logData({ message: `analytics-broker-process tracking finished` }); - process.disconnect(); + $injector.dispose(); process.exit(); };