diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex index a62154b34e..4f25c8418e 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex @@ -74,8 +74,10 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckPortConnectivityCommand do |> Enum.sort() |> Enum.join(", ") - {:ok, "Successfully connected to ports #{ports} on node #{node_name} (using node hostname resolution)"} + {:ok, + "Successfully connected to ports #{ports} on node #{node_name} (using node hostname resolution)"} end + def output({true, listeners}, %{node: node_name, address: target_ip}) do ports = listeners @@ -84,7 +86,8 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckPortConnectivityCommand do |> Enum.sort() |> Enum.join(", ") - {:ok, "Successfully connected to ports #{ports} on node #{node_name} (using #{target_ip} for target IP address)"} + {:ok, + "Successfully connected to ports #{ports} on node #{node_name} (using #{target_ip} for target IP address)"} end def output({false, failures}, %{formatter: "json", node: node_name}) do @@ -110,6 +113,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckPortConnectivityCommand do def banner([], %{node: node_name, address: nil}) do "Testing TCP connections to all active listeners on node #{node_name} using hostname resolution ..." end + def banner([], %{node: node_name, address: target_ip}) do "Testing TCP connections to all active listeners on node #{node_name} using #{target_ip} for node IP address ..." end diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex index 8f7b45bde3..3135407eea 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex @@ -7,6 +7,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Helpers do def test_connection(hostname_or_ip, port, timeout) do hostname_as_list = :rabbit_data_coercion.to_list(hostname_or_ip) + case :gen_tcp.connect(hostname_as_list, port, [], timeout) do {:error, _} -> :gen_tcp.connect(hostname_as_list, port, [:inet6], timeout) r -> r @@ -17,16 +18,17 @@ defmodule RabbitMQ.CLI.Diagnostics.Helpers do check_port_connectivity(port, node_name, nil, timeout) end - def check_port_connectivity(port, node_name, nil, timeout) do regex = Regex.recompile!(~r/^(.+)@/) hostname = Regex.replace(regex, to_string(node_name), "") |> to_charlist check_port_connectivity(port, node_name, hostname, timeout) end + def check_port_connectivity(port, node_name, hostname_or_ip, timeout) do try do IO.puts("Will connect to #{hostname_or_ip}:#{port}") + case test_connection(hostname_or_ip, port, timeout) do {:error, err} -> IO.puts("Error connecting to #{hostname_or_ip}:#{port}: #{err}")