ZhouJunjun opened a new issue #637: URL: https://github.com/apache/rocketmq-client-go/issues/637
Sometimes value of utils.LocalIp is a loopback ip, cause in line 48:!ipnet.IP.IsLoopback() is only hit ip like 127.* or ::1 If some of server's net interface is a loopback interface, value of utils.LocalIp might be a loopback ip(which is not like 127.*) [https://github.com/apache/rocketmq-client-go/blob/master/internal/utils/net.go#L29-L54](https://github.com/apache/rocketmq-client-go/blob/master/internal/utils/net.go#L29-L54) so i think ClientIP4() should filter lookback interface first like this: ``` func GetLocalServerIp() (string, error) { if ifaceSlice, err := net.Interfaces(); err == nil && ifaceSlice != nil { for _, iface := range ifaceSlice { if iface.Flags&net.FlagLoopback != 0 { continue // loopback interface } if iface.Flags&net.FlagUp == 0 { continue // interface down } if tmpAddrSlice, err := iface.Addrs(); err == nil && tmpAddrSlice != nil { for _, address := range tmpAddrSlice { if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() { if ipNet.IP.To4() != nil { return ipNet.IP.String(), nil } } } } } } return "", fmt.Errorf("eth0 not found")` ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
