mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-03-01 01:13:16 +08:00
Fix runtime failing to connect when using ipv6 and epmd-less
Regression from #2923.
This commit is contained in:
parent
08a0f1e14a
commit
33b040a8e3
1 changed files with 13 additions and 7 deletions
|
@ -33,6 +33,7 @@ defmodule Livebook.Runtime.EPMD do
|
|||
|
||||
def register_node(name, port, family) do
|
||||
:persistent_term.put(:livebook_dist_port, port)
|
||||
:persistent_term.put(:livebook_dist_family, family)
|
||||
|
||||
case :erl_epmd.register_node(name, port, family) do
|
||||
{:ok, creation} -> {:ok, creation}
|
||||
|
@ -50,7 +51,7 @@ defmodule Livebook.Runtime.EPMD do
|
|||
# If the target node is on the same host, check if it's a Livebook
|
||||
# server or runtime to bypass EPMD. If it is a different node, we
|
||||
# always fall back to :erl_epmd, even if it's a Livebook node.
|
||||
if host_to_ip(host()) == host_to_ip(host) do
|
||||
if host_to_ip!(host()) == host_to_ip!(host) do
|
||||
case livebook_port(name) do
|
||||
0 -> :erl_epmd.port_please(name, host, timeout)
|
||||
port -> {:port, port, @epmd_dist_version}
|
||||
|
@ -68,13 +69,18 @@ defmodule Livebook.Runtime.EPMD do
|
|||
import Record
|
||||
defrecordp :hostent, Record.extract(:hostent, from_lib: "kernel/include/inet.hrl")
|
||||
|
||||
defp host_to_ip(host) when is_tuple(host), do: {:ok, host}
|
||||
defp host_to_ip(host) when is_atom(host), do: host_to_ip(Atom.to_charlist(host))
|
||||
defp host_to_ip!(host) when is_tuple(host), do: host
|
||||
defp host_to_ip!(host) when is_atom(host), do: host_to_ip!(Atom.to_charlist(host))
|
||||
|
||||
defp host_to_ip(host) when is_list(host) do
|
||||
case :inet.gethostbyname(host) do
|
||||
{:ok, hostent(h_addrtype: :inet, h_addr_list: [ip | _])} -> {:ok, ip}
|
||||
_other -> :error
|
||||
defp host_to_ip!(host) when is_list(host) do
|
||||
family = :persistent_term.get(:livebook_dist_family)
|
||||
|
||||
case :inet.gethostbyname(host, family) do
|
||||
{:ok, hostent(h_addrtype: ^family, h_addr_list: [ip | _])} ->
|
||||
ip
|
||||
|
||||
other ->
|
||||
raise "failed to resolve hostname #{inspect(host)}, reason: #{inspect(other)}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue