dantswain

dantswain

Distributed Erlang same node with different host names?

Hi! I was wondering if anyone knows if it’s possible to connect two nodes when the connection node host name differs from the configured node host name?

The context here is deployment in a docker cluster, but I can reproduce this locally without docker.

For example, suppose my local network IP is 192.168.1.186:

# in terminal 1
iex --name node1@192.168.1.186
# in terminal 2
iex --name node2@192.168.1.186

Then I can connect to node 2 from node 1 as expected if I use that IP:

iex(node1@192.168.1.186)3> Node.connect(:"node2@192.168.1.186")
true
iex(node1@192.168.1.186)4> Node.list()                         
[:"node2@192.168.1.186"]

However, if I try to connect using `127.0.0.1, it fails to connect:

iex(node1@192.168.1.186)3> Node.connect(:"node2@127.0.0.1")
false
iex(node1@192.168.1.186)4> Node.list()                         
[]

I’ve done a bit of digging on this using recon_trace on the dist_util module and it seems to fail to connect during the handshake step. I was thinking maybe the cookie value gets hashed with the node name somehow, but it doesn’t look like that’s the case.

If nothing else, I’m curious if anyone can explain what’s going on here just for my own education. I was able to work around this in my deployments, but I’d love to understand better.

Thanks!

Most Liked

cmkarlsson

cmkarlsson

This is often a source of confusion.
The node name is the full name. You can’t split it up in a name and hostname/ip. If you named your node node1@192.168.1.186 then you must use the full name to connect. You can’t replace 192.168.1.186 with another IP to the same host or to a hostname. I don’t know why it was designed this way.

If you must connect to a node using different IP addresses you need to setup DNS and have it resolve differently. And the DNS needs to be FQDN (which is not quite true, but it must have a dot in the name)

dantswain

dantswain

I don’t think it’s epmd, for a couple reasons. First, I can see the connection being initiated in the trace on both nodes, so it is at least attempting an actual connection to the node. Second, I have reproduced this experiment with epmd disabled (replaced with a different implementation) and gotten the same results. Possibly it’s not finding the node in epmd and then making some kind of broadcast attempt to connect?

I agree it seems that somewhere there is a check on the literal value of the node name. It seems to happen after an initial connection attempt is made - ie some part of the stack does split the host part of the name off from the whole thing, but the handshake appears to check for it. I was hoping someone could explain just for the sake of education as I couldn’t find anything in the docs that would explain.

Fwiw I did get my set up to work using a forked version of caravan GitHub - uberbrodt/caravan: epmd implementation and other OTP apps to make running Erlang/Elixir apps with Nomad and Consul easier.

dantswain

dantswain

I redid my experiment with 3 nodes, again using tracing to see connection activity on all 3 nodes simultaneously. When node1 attempts to connect to node2, I see activity on node2 and not node3, and likewise trying to connect to node3 results in activity on node3 and not node2. So epmd does appear to be matching up the connection based on the first (before the @) part of the node name.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

We're in Beta

About us Mission Statement