From df83e66d5ce97cfcf28c1a815d567090cceda622 Mon Sep 17 00:00:00 2001 From: alanw Date: Fri, 16 Jan 2026 04:20:46 +0000 Subject: [PATCH] fix(ResourceMonitoringService): initialize fd check time and count on start --- .../cli/src/services/ResourceMonitoringService.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/extensions/cli/src/services/ResourceMonitoringService.ts b/extensions/cli/src/services/ResourceMonitoringService.ts index ed86f7f0b..a08a15f2f 100644 --- a/extensions/cli/src/services/ResourceMonitoringService.ts +++ b/extensions/cli/src/services/ResourceMonitoringService.ts @@ -45,7 +45,7 @@ class ResourceMonitoringService { private maxHistorySize = 300; // Keep 5 minutes at 1s intervals private lastCpuUsage = process.cpuUsage(); private lastTimestamp = Date.now(); - private lastFdCheckTime = 0; + private lastFdCheckTime = Date.now(); private fdCheckIntervalMs = 5000; // Check file descriptors every 5 seconds private cacheFileCount: number | null = null; @@ -73,6 +73,12 @@ class ResourceMonitoringService { this.lastCpuUsage = process.cpuUsage(); this.lastTimestamp = Date.now(); + // Initialize file descriptor count on start + this.updateFileDescriptorCount().catch(() => { + // Ignore errors during initialization + }); + this.lastFdCheckTime = Date.now(); + this.monitoringInterval = setInterval(() => { this.collectResourceUsage(); }, this.intervalMs); @@ -130,11 +136,7 @@ class ResourceMonitoringService { }, }; - // Initialize file descriptor count on start - this.updateFileDescriptorCount().catch(() => { - // Ignore errors during initialization - }); - + // Use cached file descriptor count to avoid lsof command leak if (this.cacheFileCount !== null) { usage.fileDescriptors = this.cacheFileCount; }