Skip to content

Commit 9ca9c3e

Browse files
committed
fixup! fix: detect JetBrains running on local ipv6
1 parent 4e5f54c commit 9ca9c3e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

agent/agentssh/portinspection_supported.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ func getListeningPortProcessCmdline(port uint32) (string, error) {
1515
acceptFn := func(s *netstat.SockTabEntry) bool {
1616
return s.LocalAddr != nil && uint32(s.LocalAddr.Port) == port
1717
}
18-
tabs, err := netstat.TCPSocks(acceptFn)
18+
tabs4, err4 := netstat.TCPSocks(acceptFn)
1919
tabs6, err6 := netstat.TCP6Socks(acceptFn)
2020

21-
// Only return the error if the other method found nothing.
22-
if (err != nil && len(tabs6) == 0) || (err6 != nil && len(tabs) == 0) {
23-
return "", xerrors.Errorf("inspect port %d: %w", port, errors.Join(err, err6))
21+
// In the common case, we want to check ipv4 listening addresses. If this
22+
// fails, we should return an error. We also need to check ipv6. The
23+
// assumption is, if we have an err4, and 0 ipv6 addresses listed, then we are
24+
// interested in the err4 (and vice versa). So return both errors (at least 1
25+
// is non-nil) if the other list is empty.
26+
if (err4 != nil && len(tabs6) == 0) || (err6 != nil && len(tabs4) == 0) {
27+
return "", xerrors.Errorf("inspect port %d: %w", port, errors.Join(err4, err6))
2428
}
2529

2630
var proc *netstat.Process
27-
if len(tabs) > 0 {
28-
proc = tabs[0].Process
31+
if len(tabs4) > 0 {
32+
proc = tabs4[0].Process
2933
} else if len(tabs6) > 0 {
3034
proc = tabs6[0].Process
3135
}

0 commit comments

Comments
 (0)