Skip to content

Commit 6bff35b

Browse files
committed
fix: use exact port matching in Windows netstat parsing
- Changed from substring match to regex-based port extraction - Prevents false positives (e.g., port 8888 matching 88880) - Parses LocalAddress column and extracts port number explicitly - Handles both IPv4 (0.0.0.0:8888) and IPv6 ([::]:8888) formats - Uses exact numeric equality comparison instead of string contains - More robust and accurate port-based process detection
1 parent 51e0704 commit 6bff35b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/kernels/deepnote/deepnoteServerStarter.node.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,15 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
742742

743743
// Parse and deduplicate PIDs
744744
for (const line of lines) {
745-
if (line.includes(`:${port}`) && line.includes('LISTENING')) {
746-
const parts = line.trim().split(/\s+/);
745+
if (!line.includes('LISTENING')) continue;
746+
const parts = line.trim().split(/\s+/);
747+
// Windows netstat columns: Proto LocalAddress ForeignAddress State PID
748+
const local = parts[1] || '';
749+
const m = local.match(/:(\d+)]?$/); // handles IPv4 and [::]:port
750+
const localPort = m ? parseInt(m[1], 10) : NaN;
751+
if (localPort === port) {
747752
const pid = parseInt(parts[parts.length - 1], 10);
748-
if (!isNaN(pid) && pid > 0) {
749-
uniquePids.add(pid);
750-
}
753+
if (!isNaN(pid) && pid > 0) uniquePids.add(pid);
751754
}
752755
}
753756

0 commit comments

Comments
 (0)