Add port-to-PID fallback chain with ss and lsof support#90
Open
EhabY wants to merge 2 commits intoyibn2008:masterfrom
Open
Add port-to-PID fallback chain with ss and lsof support#90EhabY wants to merge 2 commits intoyibn2008:masterfrom
EhabY wants to merge 2 commits intoyibn2008:masterfrom
Conversation
EhabY
commented
Mar 11, 2026
| if (err) { | ||
| reject(err) | ||
| } else { | ||
| resolve({ stdout: stdout.toString(), stderr: stderr.toString().trim() }) |
Author
There was a problem hiding this comment.
Only trimming stderr because lines are sometimes skipped for stdout
3ac9143 to
7efcc41
Compare
Linux now tries ss → netstat → lsof; macOS/FreeBSD/SunOS tries netstat → lsof. Fixes lookup on distros without netstat and on non-root users where PID fields are empty.
Extract shared execCmd (promise wrapper for utils.exec) and matchPort (port-matching predicate) helpers to reduce boilerplate across all platform finders.
7efcc41 to
a261c30
Compare
Author
|
@yibn2008 Hey! I've created this PR with some mock testing for the fallback logic. Would you mind taking a look? The first commit introduces the fallout logic but the second commit does some refactoring (we repeat a lot of the logic so I just created two functions to make it easier to read). Let me know if I should change anything here! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ssandlsofas fallback tools for port-to-PID resolutionss -tunlp→netstat -tunlp→lsof -nP -i :<port>netstat -anv→lsof -nP -i :<port>netstaton Linux resolves withNaNwhen PID field is-(non-root)netstatstderr on macOS rejects instead of allowing fallbackexecCmdandmatchPorthelpers to reduce boilerplate across all platform findersThe first commit introduces the fallback logic + tests while the second commit is just refactoring some code
Motivation
netstatis deprecated on many Linux distros in favor ofss, and running without root often produces empty PID fields. This change adds a try-and-fallback chain so port lookup works in more environments without requiring any specific tool to be installed.