Repository navigation
perf(server): avoid expensive Windows listener probes - #19299
daniyal-sh wants to merge 1 commit into
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a contained Windows-only performance fix that replaces costly listener probing with a lightweight netstat path and bounded caching/backoff, while preserving configured URL probing. The production logic stays within the existing scanner and is accompanied by targeted unit and Windows integration coverage. You can add or adjust custom eligibility rules. Learn more. |
|
Note Written by Thanks for investigating Windows listener discovery. The netstat replacement, cache, and retry backoff target scan performance, while the timings measure the command rather than the preview-discovery user path. Right now we are only taking focused bug fixes from outside contributors, as allowed by our limited review capacity in Read this first. Please preserve the slow-discovery case in an issue and agree on a focused scope with us before requesting reconsideration with before/after evidence through preview discovery. |
Problem
Windows preview discovery starts PowerShell/WMI to enumerate TCP listeners and resolve process names on each scan. On this Windows machine, the original command took a median 3,706 ms with 200 added listeners. Preview discovery needs PID ownership; the expensive process-name resolution is unnecessary for finding terminal-owned web servers.
Change
Use one
netstat.exe -anocall for IPv4/IPv6 listeners, identify listening rows by their empty remote endpoint so parsing works with localized state labels, and keep process names nullable. Cache the raw table for three seconds while applying current terminal ownership on every read. Skip process discovery when no terminal PIDs are registered, retain configured-URL probes, and back off failed/truncated/timed-out scans from five seconds to one minute. Unowned ports remain excluded from HTTP probing.Scope and approval
This is a focused performance fix for the existing Windows preview scanner, limited to its implementation and regression tests. It is submitted under the focused obvious-defect exception: recurring scans launch an expensive WMI query for data the scanner does not require. No new capability or setting is introduced; no prior maintainer approval is claimed.
Related open alternative: #18524. This version uses one netstat call, avoids extra tasklist name lookups, and adds raw-table coalescing, current-owner filtering, and failure backoff.
Verification
vp test run apps/server/src/preview/PortScanner.test.ts: 28 passed on Windows, including a real owned HTTP listener through the process runner. Coverage includes localized IPv4/IPv6 rows, shared/unowned ports, zero spawns without owners, cache coalescing, changed ownership, and retry recovery.107f6024on Windows, Node 24.19.0; the submitted source is based on current main8b460a3c.Post-rebase validation on this branch at upstream main
8b460a3c(Effect 4.0.4): 28 scanner tests passed;vp run --filter t3 typecheck, changed-file lint,vp fmt --check, andgit diff --checkpassed.Implemented and validated using GPT-6.1 Sol in T3 Code through the Codex harness.