You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by 徐靖峰 <ki...@foxmail.com> on 2019/04/04 09:21:10 UTC

[DISCUSS] The logic of NetUtils.getLocalHost

Hi,
I notice that recently there are some issue about NetUtils.getLocalHost, someone complains about that logic changes bring by 
issue: https://github.com/apache/incubator-dubbo/issues/538 <https://github.com/apache/incubator-dubbo/issues/538> 
pr: https://github.com/apache/incubator-dubbo/pull/3520 <https://github.com/apache/incubator-dubbo/pull/3520>
The change places in 2.7.1 is NetUtils.getLocalHost add a new check method: 
> static boolean isValidPublicAddress(InetAddress address) {
>     return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
> }
This will exclude local site address like:
10/8 prefix
172.16/12 prefix
192.168/16 prefix
so a internal  ip 172.161.3.4 will successfully register into registry before, but will register localhost(mostly 127.0.0.1) into registry if no public ip exists.

Action:
1. Add a param switch let user choose to prefer to register local site address or public address.
2. The  default priority to find useful address in multi network cards can be : public > internal > localhost. 

Re: [DISCUSS] The logic of NetUtils.getLocalHost

Posted by Ian Luo <ia...@gmail.com>.
Kirito,

Pls. note NetUtils.getLocalHost intends to return the valid public address
which can be able to be discoverable from the registry center.

The current behavior is: if there's no public address found, then 127.0.0.1
will be used as fallback value:

```
public static String getLocalHost() {
    InetAddress address = getLocalAddress();
    return address == null ? Constants.LOCALHOST_VALUE :
address.getHostAddress();
}
```

When there are multiple network interfaces, the first resolved public
address will be returned. This behavior will lead to dubbo sometimes return
the address from the virtual network interface, usually configured by
virtual machine.

So my suggestions are:
1. Should we throw IllegalStateException when there's no public address
found instead of falling back to localhost?
2. How can we distinguish virtual network interfaces accurately from others?

Thanks,
-Ian.



On Thu, Apr 4, 2019 at 5:21 PM 徐靖峰 <ki...@foxmail.com> wrote:

> Hi,
> I notice that recently there are some issue about NetUtils.getLocalHost,
> someone complains about that logic changes bring by
> issue: https://github.com/apache/incubator-dubbo/issues/538 <
> https://github.com/apache/incubator-dubbo/issues/538>
> pr: https://github.com/apache/incubator-dubbo/pull/3520 <
> https://github.com/apache/incubator-dubbo/pull/3520>
> The change places in 2.7.1 is NetUtils.getLocalHost add a new check
> method:
> > static boolean isValidPublicAddress(InetAddress address) {
> >     return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
> > }
> This will exclude local site address like:
> 10/8 prefix
> 172.16/12 prefix
> 192.168/16 prefix
> so a internal  ip 172.161.3.4 will successfully register into registry
> before, but will register localhost(mostly 127.0.0.1) into registry if no
> public ip exists.
>
> Action:
> 1. Add a param switch let user choose to prefer to register local site
> address or public address.
> 2. The  default priority to find useful address in multi network cards can
> be : public > internal > localhost.

Re: [DISCUSS] The logic of NetUtils.getLocalHost

Posted by 徐靖峰 <ki...@foxmail.com>.
I want take the both two actions~ 

> 在 2019年4月4日,下午5:40,YunKun Huang <hy...@apache.org> 写道:
> 
> I prefer option 2. but I think we need a warn message if no public ip exist to let user know this behaviour?
> 
> On 2019/04/04 09:21:10, 徐靖峰 <ki...@foxmail.com> wrote: 
>> Hi,
>> I notice that recently there are some issue about NetUtils.getLocalHost, someone complains about that logic changes bring by 
>> issue: https://github.com/apache/incubator-dubbo/issues/538 <https://github.com/apache/incubator-dubbo/issues/538> 
>> pr: https://github.com/apache/incubator-dubbo/pull/3520 <https://github.com/apache/incubator-dubbo/pull/3520>
>> The change places in 2.7.1 is NetUtils.getLocalHost add a new check method: 
>>> static boolean isValidPublicAddress(InetAddress address) {
>>>    return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
>>> }
>> This will exclude local site address like:
>> 10/8 prefix
>> 172.16/12 prefix
>> 192.168/16 prefix
>> so a internal  ip 172.161.3.4 will successfully register into registry before, but will register localhost(mostly 127.0.0.1) into registry if no public ip exists.
>> 
>> Action:
>> 1. Add a param switch let user choose to prefer to register local site address or public address.
>> 2. The  default priority to find useful address in multi network cards can be : public > internal > localhost. 
> 


Re:Re: [DISCUSS] The logic of NetUtils.getLocalHost

Posted by 秦金卫 <ki...@163.com>.
I remenber several users want to register Domain name instead of IP across docker env.


At 2019-04-04 18:32:15, "徐靖峰" <ki...@foxmail.com> wrote:
>Agree, warn log is needed.
>
>> 在 2019年4月4日,下午5:40,YunKun Huang <hy...@apache.org> 写道:
>> 
>> I prefer option 2. but I think we need a warn message if no public ip exist to let user know this behaviour?
>> 
>> On 2019/04/04 09:21:10, 徐靖峰 <ki...@foxmail.com> wrote: 
>>> Hi,
>>> I notice that recently there are some issue about NetUtils.getLocalHost, someone complains about that logic changes bring by 
>>> issue: https://github.com/apache/incubator-dubbo/issues/538 <https://github.com/apache/incubator-dubbo/issues/538> 
>>> pr: https://github.com/apache/incubator-dubbo/pull/3520 <https://github.com/apache/incubator-dubbo/pull/3520>
>>> The change places in 2.7.1 is NetUtils.getLocalHost add a new check method: 
>>>> static boolean isValidPublicAddress(InetAddress address) {
>>>>    return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
>>>> }
>>> This will exclude local site address like:
>>> 10/8 prefix
>>> 172.16/12 prefix
>>> 192.168/16 prefix
>>> so a internal  ip 172.161.3.4 will successfully register into registry before, but will register localhost(mostly 127.0.0.1) into registry if no public ip exists.
>>> 
>>> Action:
>>> 1. Add a param switch let user choose to prefer to register local site address or public address.
>>> 2. The  default priority to find useful address in multi network cards can be : public > internal > localhost. 
>> 

Re: [DISCUSS] The logic of NetUtils.getLocalHost

Posted by 徐靖峰 <ki...@foxmail.com>.
Agree, warn log is needed.

> 在 2019年4月4日,下午5:40,YunKun Huang <hy...@apache.org> 写道:
> 
> I prefer option 2. but I think we need a warn message if no public ip exist to let user know this behaviour?
> 
> On 2019/04/04 09:21:10, 徐靖峰 <ki...@foxmail.com> wrote: 
>> Hi,
>> I notice that recently there are some issue about NetUtils.getLocalHost, someone complains about that logic changes bring by 
>> issue: https://github.com/apache/incubator-dubbo/issues/538 <https://github.com/apache/incubator-dubbo/issues/538> 
>> pr: https://github.com/apache/incubator-dubbo/pull/3520 <https://github.com/apache/incubator-dubbo/pull/3520>
>> The change places in 2.7.1 is NetUtils.getLocalHost add a new check method: 
>>> static boolean isValidPublicAddress(InetAddress address) {
>>>    return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
>>> }
>> This will exclude local site address like:
>> 10/8 prefix
>> 172.16/12 prefix
>> 192.168/16 prefix
>> so a internal  ip 172.161.3.4 will successfully register into registry before, but will register localhost(mostly 127.0.0.1) into registry if no public ip exists.
>> 
>> Action:
>> 1. Add a param switch let user choose to prefer to register local site address or public address.
>> 2. The  default priority to find useful address in multi network cards can be : public > internal > localhost. 
> 


Re: [DISCUSS] The logic of NetUtils.getLocalHost

Posted by YunKun Huang <hy...@apache.org>.
I prefer option 2. but I think we need a warn message if no public ip exist to let user know this behaviour?

On 2019/04/04 09:21:10, 徐靖峰 <ki...@foxmail.com> wrote: 
> Hi,
> I notice that recently there are some issue about NetUtils.getLocalHost, someone complains about that logic changes bring by 
> issue: https://github.com/apache/incubator-dubbo/issues/538 <https://github.com/apache/incubator-dubbo/issues/538> 
> pr: https://github.com/apache/incubator-dubbo/pull/3520 <https://github.com/apache/incubator-dubbo/pull/3520>
> The change places in 2.7.1 is NetUtils.getLocalHost add a new check method: 
> > static boolean isValidPublicAddress(InetAddress address) {
> >     return !address.isSiteLocalAddress() && !address.isLoopbackAddress();
> > }
> This will exclude local site address like:
> 10/8 prefix
> 172.16/12 prefix
> 192.168/16 prefix
> so a internal  ip 172.161.3.4 will successfully register into registry before, but will register localhost(mostly 127.0.0.1) into registry if no public ip exists.
> 
> Action:
> 1. Add a param switch let user choose to prefer to register local site address or public address.
> 2. The  default priority to find useful address in multi network cards can be : public > internal > localhost.