Skip to content

Commit

Permalink
fix: Use inet6 when host requires it (#778)
Browse files Browse the repository at this point in the history
Fixes bug where inet (IP V4) was being used instead of inet6 (IP V6) due to badly set connection configuration.
  • Loading branch information
filipecabaco authored Jan 18, 2024
1 parent 7f3aa93 commit 357bbf5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/realtime/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ defmodule Realtime.Helpers do
name = settings["db_name"]
user = settings["db_user"]
password = settings["db_password"]
socket_opts = settings["db_socket_opts"]
socket_opts = [detect_ip_version(host)]

opts = %{
host: host,
Expand Down Expand Up @@ -379,6 +379,26 @@ defmodule Realtime.Helpers do
end)
end

@doc """
Detects the IP version for a given host.
## Examples
iex> Realtime.Helpers.detect_ip_version("example.com")
:inet
iex> Realtime.Helpers.detect_ip_version("ipv6.example.com")
:inet6
"""
@spec detect_ip_version(String.t()) :: :inet | :inet6
def detect_ip_version(host) when is_binary(host) do
host = String.to_charlist(host)

case :inet.gethostbyname(host) do
{:ok, _} -> :inet
_ -> :inet6
end
end

defp stop_user_tenant_process(tenant, platform_region, acc) do
Extensions.PostgresCdcRls.handle_stop(tenant, 5_000)
# credo:disable-for-next-line
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.25.56",
version: "2.25.57",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 357bbf5

Please sign in to comment.