Skip to content

Commit f8443f8

Browse files
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.
1 parent 84a516c commit f8443f8

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/detached-processes/cleanup-process.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ process.on("message", async (cleanupProcessMessage: ICleanupMessageBase) => {
166166
process.on("disconnect", async () => {
167167
fileLogService.logData({ message: "cleanup-process received process.disconnect event" });
168168
await executeCleanup();
169+
$injector.dispose();
170+
process.exit();
169171
});
170172

171173
fileLogService.logData({ message: `cleanup-process will send ${DetachedProcessMessages.ProcessReadyToReceive} message` });

lib/services/analytics/analytics-broker-process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const finishTracking = async (data?: ITrackingInformation) => {
2929
analyticsLoggingService.logData({ message: `analytics-broker-process finish tracking started` });
3030
await trackingQueue;
3131
analyticsLoggingService.logData({ message: `analytics-broker-process tracking finished` });
32-
process.disconnect();
32+
$injector.dispose();
3333
process.exit();
3434
};
3535

0 commit comments

Comments
 (0)