From 58be26fe48bc69af4f38d411aa14524fb0cbce74 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 4 May 2026 10:07:28 -0500 Subject: [PATCH] fix(pskr): force IPv4 on broker connect K8s pods have IPv4-only egress; without :inet in the gen_tcp opts, BEAM was picking mqtt.pskreporter.info's AAAA record and the kernel's connect() returned EINVAL, surfacing as :einval and a 30-second retry loop. --- lib/microwaveprop/pskr/client.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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)),