Repository navigation
Description
Summary
With a UDP listener + UDP cluster configured with the default UdpClusterConfig (so affinity_key unset → SOURCE_IP), Sōzu:
- merges every client coming from the same source IP into a single flow, whatever their source port, over a single connected upstream socket;
- sends every backend reply to the source port of the first client that created the flow, not to the client that sent the datagram. Once that first client socket is gone, no client from that IP ever gets a reply again;
- never expires that flow: it survived >15 min of complete silence and ~30 min overall, with
front_timeout/back_timeout= 30 s on the listener.
The net effect is that UDP load balancing is broken for any client IP after its first flow. It is especially bad behind NAT/CGNAT, where many clients share one IP (e.g. WebRTC/LiveKit, DNS resolvers).
This seems to contradict the design in #1273 ("Virtual 4-tuple flow sessions", idle timeout teardown, "one connected socket per flow (the connected fd is the NAT-return demux key)").
Environment
- Sōzu 2.2 (configured through
sozu-command-lib2.2.0 from a control-plane agent, via the command socket) - Linux, Sōzu running in a dedicated network namespace
- UDP listener on
VIP:9090,front_timeout = 30,back_timeout = 30,max_rx_datagram_size = 1500,max_flows = 0 - Cluster:
load_balancing = HRW,udp = UdpClusterConfig::default()(all fieldsNone) - 3 backends (Kubernetes NodePort; the backend is a trivial UDP echo server that replies to the datagram's source address)
Reproduction
- Send one datagram from client socket
C0(source portP0) → you get a reply. CloseC0. - From the same IP, open two new sockets
A(portPa) andB(portPb) and alternate datagrams. - Neither
AnorBever gets a reply. Waiting >>front_timeout(tested with 150 s and ~15 min of silence) doesn't help.
Evidence
tcpdump inside the Sōzu netns. The client IP is anonymized as 198.51.100.7 and the VIP as 203.0.113.8; the other addresses are real. The client sockets are A = port 50376 and B = port 50644:
17:10:38.294726 pub In IP 198.51.100.7.50376 > 203.0.113.8.9090: UDP, length 2 <- client A
17:10:38.294810 wg Out IP 10.112.0.8.40217 > 10.112.0.10.31170: UDP, length 2 <- to backend
17:10:38.297044 wg In IP 10.112.0.10.31170 > 10.112.0.8.40217: UDP, length 38 <- backend reply OK
17:10:38.297133 pub Out IP 203.0.113.8.9090 > 198.51.100.7.61203: UDP, length 38 <- WRONG port (should be 50376)
17:10:40.299681 pub In IP 198.51.100.7.50644 > 203.0.113.8.9090: UDP, length 2 <- client B
17:10:40.299797 wg Out IP 10.112.0.8.40217 > 10.112.0.10.31170: UDP, length 2 <- same upstream socket
17:10:40.302070 wg In IP 10.112.0.10.31170 > 10.112.0.8.40217: UDP, length 38
17:10:40.302128 pub Out IP 203.0.113.8.9090 > 198.51.100.7.61203: UDP, length 38 <- WRONG port (should be 50644)
... (same pattern for 90 datagrams over 3 minutes, 0 replies reach A or B)
61203 is the port of a client socket that sent a single datagram ~30 min earlier and was closed right after. It was the only client that ever got a reply.
ss -uanpe in the netns shows one upstream socket for the whole listener/cluster:
ESTAB 0 0 10.112.0.8:40217 10.112.0.10:31170 users:(("10",pid=2835,fd=12)) # Sōzu worker
UNCONN 0 0 203.0.113.8:9090 0.0.0.0:* users:(("10",pid=2835,fd=11)) # Sōzu worker
UNCONN 0 0 *:9090 *:* users:(("10",pid=2835,fd=13)) # Sōzu worker
That same upstream socket 10.112.0.8:40217 was used for every datagram from this client IP for ~30 min. The backend-side capture confirms that every datagram arrives from 10.112.0.8:40217 and that the backend replies to it.
The second VIP of the same load balancer shows the same symptoms: a single upstream socket (10.112.0.9:55004) for all clients of one IP, seen from the backend side, and no reply reaching the client.
Expected
- The flow is keyed on the client 4-tuple, or at least the reply is sent to the source address of the client datagram that is being answered.
SOURCE_IPaffinity should only influence backend selection (HRW/Maglev hash), not merge distinct client sockets into one flow whose return address is frozen. - An idle flow is torn down after the idle timeout, so its upstream socket is closed and a new flow (new upstream socket) is created for the next datagram.
Notes / questions
- Is
affinity_key = SOURCE_IPsupposed to key the flow table, or only the backend hash? If it's the flow table, the default makes UDP unusable behind NAT, and the reply address should at least be updated to the latest client source. - On our side we plan to work around it by setting
affinity_key = SOURCE_IP_PORTexplicitly. The idle-expiry problem (point 3) probably exists independently of the key.
Activity
P4ndaFR commentedon Oct 1, 2026
Update after redeploying (Sōzu worker restarted, so the flow table was fresh): points 1 and 2 are no longer reproducible, but point 3 (idle flows never torn down) is confirmed.
Points 1 & 2: OK now
From a single client IP, two sockets
AandBalternating, plus 30 fresh sockets (one datagram each), against203.0.113.8:9090:10.112.0.8:<port>seen by the backends), spread over all backends.So with this setup flows are keyed on the client ip:port. (I can't tell from the outside whether that comes from an explicit
affinity_key = SOURCE_IP_PORTon our side or from a change in Sōzu itself. The question in the original report about whatSOURCE_IPis supposed to key still stands.)Point 3: idle flows are never closed
Listener
front_timeout = 30,back_timeout = 30,max_flows = 0.Sequence:
That's 33 flows in total. A few minutes after the last datagram (all flows idle well past 30 s),
ss -uanpein the Sōzu netns shows 33 connected upstream sockets, i.e. every flow ever created since the restart:(33 lines, fds 15 to 47, none closed.)
Impact
Now that each client socket gets its own flow, the leak grows with each client socket instead of with each client IP. With
max_flows = 0, the worker keeps accumulating connected UDP sockets until it hitsRLIMIT_NOFILE. That affects any UDP workload where clients use ephemeral ports per request (DNS) or many short sessions (WebRTC/TURN).Expected: an idle flow is reaped after the idle timeout and its upstream socket is closed, as described in #1273 (three-knob teardown, idle
timeout, timer wheel with generation tokens).fix(udp): key flows on the client source address, not on the affinity…
fix(udp): key flows on the client source address, not on the affinity…
fix(udp): key flows on the client source address, not on the affinity…
FlorentinDUBOIS commentedon Oct 1, 2026
Update: #1746 is merged into
main(fcdec35).mainby 596b3ec. Idle flows are torn down according to the listenerfront_timeout/back_timeout. There is no configuration workaround on 2.2.x.max_connections_per_ip/max_connections_per_subnet, opt-in per cluster) is in progress in feat(udp): cap concurrent flows per source address and subnet #1770.FlorentinDUBOIS commentedon Oct 2, 2026
Follow-up: the opt-in per-source UDP flow cap is merged in #1770 (
99e6aee2). A UDP cluster's ownmax_connections_per_ip/max_connections_per_subnetnow cap concurrent flows per source address and subnet; the global defaults do not apply to UDP. Not yet in a release.fix(udp): key flows on the client source address, not on the affinity…