Resolve pm2 ports from listening sockets instead of env vars#29
Merged
Conversation
Port detection previously read the bare PORT or any *_PORT env var from pm2_env, preferring a specific *_PORT over PORT. Inside Conductor this latched onto the inherited CONDUCTOR_PORT allocation: it overrode an app's real PORT and gave non-server processes a phantom port. The env var is only intent; the listening socket is truth. Replace the heuristic with SocketScanner, which snapshots the machine once per refresh (one lsof + one ps) and resolves each process's ports from its own pid plus descendants — so npm-wrapped servers (pm2 start npm -- run dev), where the real listener is a child, are attributed correctly. IPv4/IPv6 bindings collapse, debug/inspector ports (9229-9231) are filtered, and the decoder no longer enumerates pm2_env at all. PM2Process.port (Int?) becomes ports ([Int]). The row shows up to two ports with a +N overflow badge and a tooltip listing all; the env header keeps its band/range, now aggregating the flattened real ports. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the row's "up to two ports, then +N" decision out of ProcessPortsView into a pure PortDisplay.summarize helper so it can be unit-tested, and cover it (0/1/2/3/many ports, custom limit, tooltip lists all). Add robustness tests for the socket parsers: orphan name lines, wildcard / non-numeric port tails, unrecognised lsof field tags, malformed ps lines, and a combined debug-filter-plus-sort case. Drop a redundant inline comment in PM2Process decoding (the same fact is already on the ports property and the extension header). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Port detection previously read the bare
PORTor any*_PORTenv var frompm2_env, which inside Conductor latched onto the inheritedCONDUCTOR_PORTallocation — overriding an app's real port and giving non-server processes a phantom one. This replaces the heuristic withSocketScanner, which resolves each process's ports from the actual listening sockets (onelsof+ onepsper refresh, machine-wide) and attributes ports opened by child processes too, so npm-wrapped servers (pm2 start npm -- run dev) resolve correctly.PM2Process.port(Int?) becomesports([Int]): the row shows up to two ports as links with a+Noverflow badge and a tooltip listing all, while the env header keeps its band/range aggregated over the real ports. The decoder no longer enumeratespm2_envat all, IPv4/IPv6 bindings collapse, and debug/inspector ports (9229–9231) are filtered. Adds a purePortDisplayhelper and tests covering socket parsing, process-tree resolution, debug filtering, and the display logic.🤖 Generated with Claude Code
Summary by cubic
Resolve PM2 ports from actual listening sockets instead of env vars to prevent phantom ports and correctly attribute child process listeners; the UI now shows up to two ports with a +N overflow and the env header aggregates real port ranges.
Bug Fixes
PORT/*_PORTfrompm2_env; useSocketScanner(onelsof+ onepsper refresh) to map ports by pid and descendants. FixesCONDUCTOR_PORTbleed-through and npm-wrapped servers.Refactors
PM2Process.portwithports: [Int]; update search, env header band/range, and rows viaProcessPortsView(shows up to two ports with a +N tooltip).PortDisplayhelper and tests for socket parsing, process-tree resolution, debug filtering, and display logic; decoder no longer enumeratespm2_env.Written for commit 74a8373. Summary will update on new commits.