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 Responses

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. · GitHub

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

Tee
can someone please explain to me how Enum.reduce works with maps
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
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 t...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New

We're in Beta

About us Mission Statement