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.
This commit is contained in:
Graham McIntire 2026-05-04 10:07:28 -05:00
parent 480cc084cf
commit 58be26fe48
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -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)),