perf(port): replace systeminformation with native TCP bind probe - #63
Open
ubadineke wants to merge 1 commit into
Open
perf(port): replace systeminformation with native TCP bind probe#63ubadineke wants to merge 1 commit into
ubadineke wants to merge 1 commit into
Conversation
failfmi
reviewed
Aug 13, 2026
| @@ -65,13 +65,12 @@ class PortManager { | |||
| } | |||
|
|
|||
| async isPortOpen(port) { | |||
Collaborator
There was a problem hiding this comment.
This method is used to wait for a fresh gdbstub listener while the current LLDB connection may still be established on the port. A bind probe can return EADDRINUSE for the established connection even when no listener exists, which will resolve the outer loop to start another debug session immediately.
Contributor
Author
There was a problem hiding this comment.
Didn't consider that, I was mainly focused on the optimization aspect, didn't take note that the same check served for fresh listeners.
Thanks, I guess you can close now.
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
isPortOpencalledsi.networkConnections(), which shells out tolsof/netstatand scans every connection on the machine just to check one port's state. Replaced with a native bind probe (net.createServer().listen()) — same "check state, don't connect" safety property, roughly 1/700th–1/4000th the cost, and drops thesysteminformationdependency, which existed for this one call.This isn't just a during-a-session optimization —
StateMonitorpolls it every 1-2s the whole time the Gimlet pane is visible, not only while actively debugging.Why not
net.connect()?A connect-based probe was actually the original implementation here, and it was deliberately removed (
7fea373) — but for a narrower reason than "avoidnet": it was being used to monitor whether an already-connected debugger session was still alive, which a fresh connect can't do.anza-xyz/sbpf's gdbstub accepts exactly one client and drops its listener right after, so any later connect attempt gets refused whether the real session is healthy or dead.netstat'sESTABLISHED-state check fixed that correctly.When
si.networkConnections()later replaced the plainnetstatcall (2488386), it was for an unrelated reason (cross-platform parsing), not because of the connect-probe bug above — but it kept the same "don't usenetfor port checks" habit anyway. That habit doesn't actually apply to the check this PR touches:isPortOpenonly checksLISTENstate before a session starts, and a bind probe is safe for it the same waynetstat/siare — it never calls.accept()on the target, just without the subprocess. Verified against a fixture mimicking the single-accept gdbstub: 0/10 probes reached its accept handler.Benchmarks
30 iterations per case, against the actual
isPortOpenin this PR vs.si.networkConnections()reconstructed from the removed implementation:netbind-probe)si.networkConnections)StateMonitor-realistic)