Description
Describe the bug
The local host name used for the node when -sname
is set does not always match what net_adm:localhost()
returns, when net_adm:localhost()
returns a short name.
To Reproduce
In all cases /etc/hostname
contains zen
.
1 When /etc/hosts
contains:
127.0.0.1 localhost
::1 localhost
127.0.0.1 zen.localdomain zen
::1 zen.localdomain zen
I get
% erl -sname abc
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help)
(abc@localhost)1> net_adm:localhost().
"zen"
(abc@localhost)2>
2 When /etc/hosts
contains:
127.0.0.1 zen.localdomain zen
::1 zen.localdomain zen
127.0.0.1 localhost
::1 localhost
I get the correct, but unconvenient:
% erl -sname abc
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help)
(abc@zen)1> net_adm:localhost().
"zen.localdomain"
(abc@zen)2>
3 When /etc/hosts
contains:
127.0.0.1 localhost
::1 localhost
127.0.0.1 zen
::1 zen
I get:
% erl -sname abc
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help)
(abc@localhost)1> net_adm:localhost().
"zen"
(abc@localhost)2>
4 Finally, only in the following case where /etc/hosts
contains:
127.0.0.1 zen
::1 zen
127.0.0.1 localhost
::1 localhost
I get the same name in both places:
% erl -sname abc
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help)
(abc@zen)1> net_adm:localhost().
"zen"
(abc@zen)2>
5 Bonus, when /etc/hosts
contains:
127.0.0.1 zen zen.localdomain
::1 zen zen.localdomain
127.0.0.1 localhost
::1 localhost
I also get the correct:
% erl -sname abc
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help)
(abc@zen)1> net_adm:localhost().
"zen"
(abc@zen)2>
Expected behavior
I expect -sname
to use zen
instead of localhost
when net_adm:localhost()
returns "zen"
. I expect -sname
to use localhost
only when net_adm:localhost()
also returns "localhost"
.
I do not necessarily expect the hosts to match when net_adm:localhost()
returns "zen.localdomain"
. That one is understandable since -sname
uses a short name. In that case I expect -sname
to be set to zen
(which it already is as seen in the second snippet). It would be more convenient if net_adm:localhost()
would return the same value though, when the short name is also configured and/or reachable.
The local host resolution algorithms should agree when possible.
Affected versions
At least OTP 26 and 27.
Additional context
This breaks slave
as that module uses remsh
only if the host isn't local and because the hosts don't match it thinks it's not local. I know this module is deprecated.