Fix shortnames not pointing to 127.0.0.1 (#625)

Someone reported an issue where their shortname
host was not pointing to 127.0.0.1, which caused
connections to fail. Therefore we also check and
detect this case.
This commit is contained in:
José Valim 2021-10-20 22:02:25 +02:00 committed by GitHub
parent af60e418c1
commit 3ab2a56924
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,27 +75,43 @@ defmodule Livebook.Application do
end end
end end
import Record
defrecordp :hostent, Record.extract(:hostent, from_lib: "kernel/include/inet.hrl")
# See https://github.com/livebook-dev/livebook/issues/302 # See https://github.com/livebook-dev/livebook/issues/302
defp validate_hostname_resolution!() do defp validate_hostname_resolution!() do
unless Livebook.Config.longname() do unless Livebook.Config.longname() do
hostname = Livebook.Utils.node_host() |> to_charlist() hostname = Livebook.Utils.node_host() |> to_charlist()
if :inet.gethostbyname(hostname) == {:error, :nxdomain} do case :inet.gethostbyname(hostname) do
Livebook.Config.abort!(""" {:error, :nxdomain} ->
your hostname "#{hostname}" does not resolve to any IP address, which indicates something wrong in your OS configuration. invalid_hostname!("your hostname \"#{hostname}\" does not resolve to an IP address")
Make sure your computer's name resolves locally or start Livebook using a long distribution name. If you are using Livebook's CLI, you can: {:ok, hostent(h_addrtype: :inet, h_addr_list: addresses)} ->
if {127, 0, 0, 1} not in addresses do
invalid_hostname!("your hostname \"#{hostname}\" does not resolve to 127.0.0.1")
end
livebook server --name livebook@127.0.0.1 _ ->
:ok
If you are running it from source, do instead:
MIX_ENV=prod elixir --name livebook@127.0.0.1 -S mix phx.server
""")
end end
end end
end end
defp invalid_hostname!(prelude) do
Livebook.Config.abort!("""
#{prelude}, which indicates something wrong in your OS configuration.
Make sure your computer's name resolves locally or start Livebook using a long distribution name. If you are using Livebook's CLI, you can:
livebook server --name livebook@127.0.0.1
If you are running it from source, do instead:
MIX_ENV=prod elixir --name livebook@127.0.0.1 -S mix phx.server
""")
end
defp set_cookie() do defp set_cookie() do
cookie = Application.fetch_env!(:livebook, :cookie) cookie = Application.fetch_env!(:livebook, :cookie)
Node.set_cookie(cookie) Node.set_cookie(cookie)