diff --git a/lib/microwaveprop/pskr/client.ex b/lib/microwaveprop/pskr/client.ex index 61511c79..9c8b0356 100644 --- a/lib/microwaveprop/pskr/client.ex +++ b/lib/microwaveprop/pskr/client.ex @@ -178,7 +178,11 @@ defmodule Microwaveprop.Pskr.Client do # ---------- Connection setup ---------- defp do_connect(state) do - tcp_opts = [:binary, active: :once, packet: :raw, keepalive: true] + # `:inet` forces IPv4 resolution + an IPv4 socket. Without + # this, BEAM can pick the broker's AAAA record while our K8s + # pod has IPv4-only egress, and `:gen_tcp.connect/4` fails + # with `:einval` from the kernel `connect()` syscall. + tcp_opts = [:binary, :inet, active: :once, packet: :raw, keepalive: true] with {:ok, socket} <- :gen_tcp.connect(@broker_host, @broker_port, tcp_opts, 10_000), :ok <- :gen_tcp.send(socket, Mqtt.connect(state.client_id, @keepalive_seconds)),