Comfy-Org / Comfy-Org/Comfy-Desktop

findLockingProcesses does not detect console process file handles on Windows

Open
#440 0 comments 0 reactions 0 assignees View on GitHub
bug windows
Dominant language
TypeScript
Stars
458
Forks
59
Avg merge
22h 18m
Merged PRs (30d)
45

Description

## Problem

The `findLockingProcesses()` function in `src/main/lib/file-lock-info.ts` uses the Windows Restart Manager API (via PowerShell inline C#) to detect which processes hold file locks. However, the RM API **only detects applications that registered with it** (GUI apps, Windows services) — it does not reliably detect arbitrary file handles from console processes like Node.js.

This was discovered when the unit test `detects a process holding a file open` in `file-lock-info.test.ts` consistently failed on Windows: a forked Node.js child holding a file open with `fs.openSync('r+')` + `fs.writeSync()` was never detected by the RM query, even with retries and delays.

## Current state

- The test is skipped on Windows (`if (process.platform === 'win32') return`) as of commit `389b6fd`
- The test passes on Linux/macOS where `lsof` correctly detects all process types
- The production code still calls the RM API on Windows — it works for its actual use case (detecting GUI apps like ComfyUI holding files open), but the test cannot exercise it with a simple Node.js child process

## Options

1. **Accept the RM limitation** — the function is best-effort and works for its real use case (detecting ComfyUI/Python processes). The skip is appropriate.
2. **Add a fallback using `handle.exe`** (Sysinternals) or `openfiles.exe` for more comprehensive detection on Windows — would require bundling or detecting the tool.
3. **Use NtQuerySystemInformation** via N-API or a bundled native addon for kernel-level handle enumeration.

## References

- File: `src/main/lib/file-lock-info.ts`
- Test: `src/main/lib/file-lock-info.test.ts`
- [Restart Manager API limitations](https://learn.microsoft.com/en-us/windows/win32/rstmgr/about-restart-manager)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.