Skip to content

Commit 5659ea0

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

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

agent/agentssh/portinspection_supported.go

+8-4
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

0 commit comments

Comments
 (0)