Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for issue: #43
Issue:
When using tree-kill on macOS within applications that frequently restart (such as NestJS in watch mode), the module fails with a spawn EBADF error. The error occurs in the buildProcessTree function when attempting to spawn child processes to get the process tree. This appears to be due to file descriptor handling issues specific to macOS.
The issue appears to be related to how spawn handles file descriptors on macOS when used recursively in rapid succession. The current implementation uses spawn to build the process tree, which can lead to file descriptor exhaustion or race conditions when processes are frequently being killed and restarted.
Fix
Uses
execSyncwith proper timeout and error handling specifically for macOS to avoid the EBADF issues. Adds a new functionbuildProcessTreeMacOSfor macOS or darwin platform