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:
parent
480cc084cf
commit
58be26fe48
1 changed files with 5 additions and 1 deletions
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue