Skip to content

MulticastSocket use invalid network interface #6733

@AlphaLxy

Description

@AlphaLxy
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.5
  • Operating System version: CentOS 7.7 (K8S v1.16.6)
  • Java version: 1.8

Steps to reproduce this issue

  1. Use multicast Registry, address: multicast://224.5.6.7:1234
  2. Start up application

Expected Result

Application start up succeed.

Actual Result

Application start up failed, stack trace

java.lang.IllegalStateException: Network is unreachable (sendto failed)
	at org.apache.dubbo.registry.multicast.MulticastRegistry.multicast(MulticastRegistry.java:238)
	at org.apache.dubbo.registry.multicast.MulticastRegistry.doRegister(MulticastRegistry.java:257)
	at org.apache.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:240)
	at org.apache.dubbo.registry.multicast.MulticastRegistry.register(MulticastRegistry.java:377)
	at org.apache.dubbo.registry.ListenerRegistryWrapper.register(ListenerRegistryWrapper.java:57)
	at org.apache.dubbo.registry.integration.RegistryProtocol.doRefer(RegistryProtocol.java:412)
	at org.apache.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:396)
	at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:70)
	at org.apache.dubbo.qos.protocol.QosProtocolWrapper.refer(QosProtocolWrapper.java:73)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:151)
	at org.apache.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
	at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:324)
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:266)
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:151)

Here's network interfaces

> ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.40.116  netmask 255.255.240.0  broadcast 192.168.47.255
        inet6 fe80::216:3eff:fe16:3eec  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:16:3e:ec  txqueuelen 1000  (Ethernet)
        RX packets 958592  bytes 1408986475 (1.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56904  bytes 4593937 (4.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1698  bytes 7096626 (6.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1698  bytes 7096626 (6.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
> ifconfig -a
dummy0: flags=130<BROADCAST,NOARP>  mtu 1500
        ether 7e:7f:fe:1a:8f:23  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.40.116  netmask 255.255.240.0  broadcast 192.168.47.255
        inet6 fe80::216:3eff:fe16:3eec  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:16:3e:ec  txqueuelen 1000  (Ethernet)
        RX packets 958636  bytes 1408991887 (1.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56941  bytes 4600900 (4.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

kube-ipvs0: flags=130<BROADCAST,NOARP>  mtu 1500
        inet 172.21.0.1  netmask 255.255.255.255  broadcast 172.21.0.1
        ether 7e:61:57:a0:de:b3  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1813  bytes 7104868 (6.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1813  bytes 7104868 (6.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

The reason is that interface kube-ipvs0 is not UP, but was set to MulticastSocket in org.apache.dubbo.common.utils.NetUtils#setInterface method.

Should use validNetworkInterfaces

@@ -471,10 +471,8 @@ public class NetUtils {
 
     public static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6) throws IOException {
         boolean interfaceSet = false;
-        Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
-        while (interfaces.hasMoreElements()) {
-            NetworkInterface i = (NetworkInterface) interfaces.nextElement();
-            Enumeration addresses = i.getInetAddresses();
+        for (NetworkInterface networkInterface : getValidNetworkInterfaces()) {
+            Enumeration addresses = networkInterface.getInetAddresses();
             while (addresses.hasMoreElements()) {
                 InetAddress address = (InetAddress) addresses.nextElement();
                 if (preferIpv6 && address instanceof Inet6Address) {

or just check UP flag

@@ -474,6 +474,9 @@ public class NetUtils {
         Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
         while (interfaces.hasMoreElements()) {
             NetworkInterface i = (NetworkInterface) interfaces.nextElement();
+            if (!i.isUp()) {
+                continue;
+            }
             Enumeration addresses = i.getInetAddresses();
             while (addresses.hasMoreElements()) {
                 InetAddress address = (InetAddress) addresses.nextElement();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions