I tried connecting two nodes per the instructions in Chapter 15 of the Programming Elixir book (Dave Thomas) on a Mac running Yosemite (10.10.3) and it refused to work unless I used the fully qualified names (iex --name [email protected]).
with short names:
TOP WINDOW
[ OTP ] $ iex --sname top@joel
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(top@joel)1> Node.connect :"bot@joel"
false
with FQ names:
[ OTP ] iex --name [email protected]
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex([email protected])1> Node.connect :"[email protected]"
true
If you use --sname, you need to either not add the "@joel" part or make sure it matches your machine name. Otherwise the runtime will be unable to lookup or find the node.
WINDOW 1:
[ OTP ] $ iex --sname top
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(top@joel)1>
WINDOW 2
iex --sname bot
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(bot@joel)1> Node.connect :"top"
false
iex(bot@joel)2> Node.connect :"top@joel"
false
iex(bot@joel)3> Node.connect :"[email protected]"
false
iex(bot@joel)4>
11:40:39.603 [error] * System NOT running to use fully qualified hostnames *
* Hostname joel.local is illegal *
After you start both nodes, can you please run: epmd -names and let us know what it returns?
[ OTP ] $ iex --sname top
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(top@joel)1> epmd --names
** (RuntimeError) undefined function: epmd/0
iex(top@joel)1> epmd -names
** (RuntimeError) undefined function: names/0
Sorry, please run it in your terminal, outside of IEx, after both nodes are started.
[ ] $ epmd -names
epmd: up and running on port 4369 with data:
name bot at port 51180
name top at port 51144
That's so weird. I have no idea why it doesn't work, everything seems to be setup properly.
yeah. go figure. oh well... if you think of something keep me in the loop.
@joel-regen I suspect /etc/hosts is missing something. You can try with @localhostwhen using -sname:
$ iex --sname top@localhost
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(top@localhost)1>
$ iex --sname bot@localhost
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(bot@localhost)1> Node.connect :top@localhost
true
iex(bot@localhost)2>
ok. that did work:
[ OTP ] $ iex --sname top@localhost
Erlang/OTP 17 [erts-6.3.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(top@localhost)1> Node.connect :"bot@localhost"
true
@pma found the issue. If @joel does not resolve to the current machine, then it certainly wouldn't work. :)
I don't use OSX, but I saw the same question on Stack Overflow so a quick search led me to http://forums.macrumors.com/threads/yosemite-10-10-hosts-file.1741422/
TL;DR - hosts file may have moved.
I was having the same problems that the OP reported and I was able to figure out a workaround based on comparing my system with one that works.
In short, I was having the exact same problem described at the top and like the OP, never got a satisfactory answer.
When I compared my system to my son's system, where --sname generated sessions work correctly, we found that on his system the command:
scutil --get HostName
Would return: HostName: not set
while on my system, it would return the default hostname of MyComputerName.local
So, as an experiment, I ran the command > scutil --set HostName _, where _ represents a space to unset the value. You'll have to become superuser for a moment for that to work.
Then I was able to start iex --sname one, and iex --sname two, and now my two nodes are able to connect and can see each other.
Previously it had only worked with the example above using one@localhost and two@localhost or by using --name with the FQN.
So, I believe that somehow if the HostName is set, as defined by scutil --get, that Elixir or Erlang is somehow getting confused. I see that this bug is closed. Should I open a new issue?
I was having exactly the same issue as the OP, I'm on Mac (El Capitan) and @brione work around worked for me as well. Nodes are connecting.
I succeeded by starting nodes with iex --sname bot@localhost and iex --sname node2@localhost and then was able to connect using iex> Node.connect :bot@localhost.
I did not find success with either of these:
iex --sname bot@grantscomputer nor iex --sname bot
I'm on OSX 10.10.5 Yosemite, Elixir 1.4.2, OTP 19. Thanks everyone.
Ran into this issue today on macOS Sierra. From what I've been able to gather, macOS stopped adding a hosts reference unless a sharing service is turned on, so the hostname is not resolving correctly.
The simplest solution I've found is to add 127.0.0.1 YOUR_HOSTNAME to /etc/hosts file.
You can find your host name by running scutil --get LocalHostName.
I hope this helps others with the same issue.
Most helpful comment
@joel-regen I suspect /etc/hosts is missing something. You can try with
@localhostwhen using-sname: