From 3a39fbd65f66c216bf3dbb6859c13fb326c520d9 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Wed, 3 Sep 2025 08:27:06 +0000 Subject: [PATCH] fix(processmonitor): Skip null pidusage entries when aggregating process-group memory/CPU to avoid errors --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/daemon/processmonitor.ts | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index fd808c7..f067b62 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-09-03 - 5.10.1 - fix(processmonitor) +Skip null pidusage entries when aggregating process-group memory/CPU to avoid errors + +- Add defensive check for null/undefined entries returned by pidusage before accessing memory/cpu fields +- Log a debug message when an individual process stat is null (process may have exited) +- Improve robustness of ProcessMonitor.getProcessGroupStats to prevent runtime exceptions during aggregation + ## 2025-09-01 - 5.10.0 - feat(daemon) Add crash log manager with rotation and integrate crash logging; improve IPC & process listener cleanup diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2bc95e8..629bf12 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tspm', - version: '5.10.0', + version: '5.10.1', description: 'a no fuzz process manager' } diff --git a/ts/daemon/processmonitor.ts b/ts/daemon/processmonitor.ts index 648219f..9074b65 100644 --- a/ts/daemon/processmonitor.ts +++ b/ts/daemon/processmonitor.ts @@ -435,8 +435,13 @@ export class ProcessMonitor extends EventEmitter { let totalMemory = 0; let totalCpu = 0; for (const key in stats) { - totalMemory += stats[key].memory; - totalCpu += Number.isFinite(stats[key].cpu) ? stats[key].cpu : 0; + // Check if stats[key] exists and is not null (process may have exited) + if (stats[key]) { + totalMemory += stats[key].memory || 0; + totalCpu += Number.isFinite(stats[key].cpu) ? stats[key].cpu : 0; + } else { + this.logger.debug(`Process ${key} stats are null (process may have exited)`); + } } this.logger.debug(