Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spawned wmic processes not exiting when using pidusage in packaged apps #186

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EthyMoney
Copy link

@EthyMoney EthyMoney commented Feb 13, 2025

Q A
Branch? stable
Bug fix? yes
New feature? no
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

With the recent addition of gwmi support on Windows, a spawn call was introduced to check for availability of wmic and switch to gwmi on failure.

This works fine by default, but introduces a new problem in cases where pidusage is being utilized in a packaged application such as with a tool like pkg or its actively maintained successor fork. In a packaged app, the spawned WMI processes don't get killed, which leads to a situation where each pidusage call creates a new process and they just infinitely stack up until the computer becomes unstable and/or runs out of memory.

I am someone who uses pidusage in packaged applications, so I found a simple solution to address this and created this PR. I modified lib/stats.js to now hold a reference to the spawned child wmic process, and I added a call to kill it in a finally block added to the try/catch. This maintains existing functionality while ensuring the child process is killed when this try/catch check is completed and works in both packaged and non-packaged environments.

For reference, this is what the task manager will look like when this situation occurs, with a new process forming on each pidusage call:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant