Skip to content

Multicast demo fails with message "Can't assign requested address" #2423

Closed

Description

@ralf0131
  • 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: master branch
  • Operating System version: macOS 10.13.6
  • Java version: 1.8

Step to reproduce this issue

  1. start the provider demo

Expected Result

Provider start success.

Actual Result

Provider start failed.

If there is an exception, please attach the exception trace:

Caused by: java.net.SocketException: Can't assign requested address
	at java.net.PlainDatagramSocketImpl.join(Native Method)
	at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)
	at java.net.MulticastSocket.joinGroup(MulticastSocket.java:323)
	at org.apache.dubbo.registry.multicast.MulticastRegistry.<init>(MulticastRegistry.java:91)
	... 24 more

If I add vm args -Djava.net.preferIPv4Stack=true, everything works fine.

Activity

  1. ralf0131 commented on Sep 2, 2018

    @ralf0131
    ContributorAuthor

    This is because there are multiple network interfaces in my macOS, both for ipv4 and ipv6:

    en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
            ether e0:ac:cb:7f:75:20
            inet6 fe80::cfb:9054:967d:13be%en0 prefixlen 64 secured scopeid 0x5
            inet 192.168.31.235 netmask 0xffffff00 broadcast 192.168.31.255
            nd6 options=201<PERFORMNUD,DAD>
            media: autoselect
            status: active
    awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
            ether 62:32:71:46:6b:2e
            inet6 fe80::6032:71ff:fe46:6b2e%awdl0 prefixlen 64 scopeid 0x7
            nd6 options=201<PERFORMNUD,DAD>
            media: autoselect
            status: active
    

    awdl0 is ipv6 only and en0 is both ipv4 and ipv6 available. However the JVM selects awdl0 as the default Network Interface in java.net.DefaultInterface#getDefault() method. So if we use a ipv4 address for multicasting, the error will occur.

    If -Djava.net.preferIPv4Stack=true is specified, JVM will avoid choosing awdl0 as default network interface. So everything will be all right.

    Enhancement

    Basically we don't want to let user to specify that vm args manually, so I'd like to propose to automatically select network interface by the input multicast address.

    If the multicast address is ipv4 address, automatically use ipv4 network address (by calling java.net.MulticastSocket#setInterface()), and vise versa.

  2. modified the milestones: 2.7.0, 2.6.4 on Sep 6, 2018
  3. zonghaishang commented on Sep 14, 2018

    @zonghaishang
    Member

    @ralf0131 When does this problem plan to fix?

  4. ralf0131 commented on Sep 17, 2018

    @ralf0131
    ContributorAuthor

    No ETA yet :(
    Do you have interest to take this?

  5. added a commit that references this issue on Jan 23, 2019
    7ff58f9
  6. modified the milestones: 3.0, 2.7.1 on Jan 23, 2019
  7. added a commit that references this issue on Jan 29, 2019
    7b529a3
  8. modified the milestones: 2.7.1, 2.6.6, 2.7.0 on Jan 30, 2019
  9. added a commit that references this issue on Mar 26, 2019
    897b80d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions