Skip to content

Commit 3d9a75b

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

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

agent/agentssh/portinspection_supported.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ 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+
tabs, 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(tabs) == 0) {
27+
return "", xerrors.Errorf("inspect port %d: %w", port, errors.Join(err4, err6))
2428
}
2529

2630
var proc *netstat.Process
@@ -41,7 +45,7 @@ func getListeningPortProcessCmdline(port uint32) (string, error) {
4145
pid := proc.Pid
4246
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
4347
if err != nil {
44-
return "", xerrors.Errorf("read /proc/%d/cmdline: %w", pid, err)
48+
return "", xerrors.Errorf("read /proc/%d/cmdline: %w", pid, err4)
4549
}
4650
return string(data), nil
4751
}

0 commit comments

Comments
 (0)