Skip to content

Hidden side-effect: GetCpuUsage mutates global state and prunes dead processes #432

@Christophe-Rogiers

Description

@Christophe-Rogiers

Description

src/Servy.Core/Helpers/ProcessHelper.cs:57GetCpuUsage(int pid) is named as a pure getter but:

  1. Calls PruneDeadProcesses() on every invocation (iterates all cached PIDs, removes dead ones)
  2. Writes a new CpuSample into the static ConcurrentDictionary on every call

A method named "Get" should not perform maintenance operations or mutate shared state.

Suggested fix

Separate the pruning into an explicit MaintainCache() method called on a timer, and rename or document the state mutation.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions