Skip to content

feat(lanes): a lane on a node relays its UDP ports (ADR-0056) - #236

Merged
7schmiede merged 3 commits into
mainfrom
feat/udp-relay
Oct 23, 2026
Merged

7schmiede merged 3 commits into
mainfrom
feat/udp-relay

Conversation

@7schmiede

@7schmiede 7schmiede commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Implements #219, the long-term part of #192: UDP ports of a lane on a pool node are forwarded to the requester, through the node tunnel.

ADR-0056 is Proposed: this PR merges once the owner accepts it.

ADR-0056, in short

  • A tunnel per session, a frame per datagram. The tunnel has no multiplexing (ADR-0029 as built: one HTTP upgrade per connection), so a UDP session is its own upgrade, Upgrade: devstack-udp, on the lane daemon's existing /v1/tunnel/{port}, spliced by the node agent like a TCP tunnel. Each datagram is a frame: its length as two bytes, big-endian, then the bytes. No session id: the tunnel is the session.
  • Requester relay: each UDP port bound on loopback (IPv4, IPv6 where there is one) at the lane's port; sessions keyed by the client's address; the first datagram opens the tunnel, up to 64 wait meanwhile, more are dropped; a tunnel that does not open drops what waited, and that client is tried again at most once a second. No hold while a container starts. At most 256 sessions per port.
  • Idle timeout 60 s without a datagram either way: inside the keepalive intervals of protocols that keep a session (15–30 s), and a one-off DNS-style exchange holds a TLS connection on the node (cap 1024) for at most a minute. Docker's UDP proxy keeps 90 s.
  • Node relay: the lane daemon opens a UDP socket per session, connected to the container's address on the lane's network; ends with the tunnel, or after 2x the idle timeout as a backstop. Port-unreachable errors lose a datagram, not the session.
  • Size/MTU: a frame carries up to 65,535 bytes, both sides read with 64 KiB buffers, so every datagram arrives whole and leaves as one datagram of the same size; the OS fragments on each end as for a local lane. A stream that ends inside a frame ends the session.
  • Lost tunnel: ends its session only; datagrams in flight are lost, the next datagram opens a new session (new source port at the container). Lease over / lane stopped / moved closes listeners and sessions, as for TCP.
  • Compatibility, asked for: the requester sends relay_udp in the start request; a node that relays writes udp into the lane daemon's file and answers infra_udp_ports. Only then does the lane daemon stop listing UDP as not_forwarded. An older requester: ports stay not_forwarded as today. An older node: nothing is relayed, and the lane says why (not_forwarded_reason). A lane carried over a restart (ADR-0052) keeps its UDP ports.
  • Out of scope: the main slot still moves TCP only (ADR-0048 point 6); shared lanes (ADR-0035/0053) share http/https services only, so there is no UDP to relay there; SCTP stays not forwarded; local lanes are unchanged (Docker publishes UDP).

ADR-0029's Related line and index row link ADR-0056.

What changes

  • crates/devstack-daemon/src/udprelay.rs (new): framing, the requester's relay and session table, the lane daemon's session.
  • Lane daemon: /v1/tunnel/{port} with devstack-udp (api.rs), infra_udp (supervisor/infra.rs), udp in the agent's file decides not_forwarded (external.rs).
  • Requester (remote.rs): UDP listeners next to the TCP ones (a shared bind-and-retry), open_tunnel for both protocols, relay_udp in the start, Carried.udp_ports, not_forwarded_reason; LaneView.not_forwarded_reason (lanes.rs).
  • Node (node.rs, lanerun.rs, nodeclient.rs): Start.relay_udp, LaneState.infra_udp_ports, udp written into the lane daemon's file.
  • CLI: devstack lane list gives the reason (UDP port 5353 is not forwarded to this machine (the node build-1 runs devstack 0.19.0, which forwards TCP only: devstack 0.20.0 or later there relays UDP)).
  • Dashboard: the lane header uses the reason; the container row/page fall back to "an older devstack forwards TCP only".
  • Docs: docs/pool.md, docs/dashboard-api.md (the devstack-udp tunnel, not_forwarded_reason), the devstack skill.
  • New dependency socket2 (MIT OR Apache-2.0, already in the lock through tokio): the relays raise a UDP socket's send and receive buffers to hold any datagram, as macOS sends at most 9 KiB by default (found by the macos-14 runner: EMSGSIZE on a 60 KB datagram).

Wire compatibility: every new field is additive with skip_serializing_if; an older peer ignores it.

Tests

  • Unit (udprelay): encode/decode, a stream cut inside a frame, the session table (keyed by client, stale ids, backoff, full), the idle timeout on both sides, a tunnel that does not open (no hold, no retry storm), a dropped relay letting its port go; in-process pipes between relay and serve with a real UDP echo socket.
  • external.rs, lanerun.rs, remote.rs (not_forwarded_reason, Carried), client.rs, ui/src/lib/lanes.test.ts.
  • End to end (crates/devstack/tests/udp_relay.rs, runs on every OS, no Docker): a real devstack daemon with DEVSTACK_EXTERNAL_INFRA naming an echo socket as the container; this machine's relay opens sessions as HTTP upgrades on its /v1/tunnel/{port}; datagrams (including 32 KB) go there and back, one session per client, a TCP-only port refused.
  • cargo fmt --all, cargo clippy --workspace --all-targets --locked -- -D warnings (Windows), and clippy for aarch64-apple-darwin and x86_64-unknown-linux-gnu: clean. cargo test for devstack-daemon (lib), devstack-node (lib and tests), devstack (bin, udp_relay), devstack-skills: pass. ui: typecheck, vitest (69), build: pass.
  • Not run: the Docker-on-Linux node tests (remote_lane.rs, lanerun.rs, opt-in), so the path through a real node agent and a real container is not exercised here.

Closes #219

🤖 Generated with Claude Code

7schmiede and others added 3 commits October 23, 2026 12:56
A UDP session is its own tunnel (`Upgrade: devstack-udp` on the lane
daemon's `/v1/tunnel/{port}`), each datagram a length-prefixed frame; the
requester keys sessions by the client's address with a 60 s idle timeout,
the lane daemon opens a socket per session towards the container. The
requester asks for it at the start, so an older peer leaves UDP ports
marked as not forwarded, with the reason. Linked from ADR-0029.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (ADR-0056)

A container port published as UDP on a lane on a node is no longer only
named as not forwarded: the requester binds it on loopback at the lane's
port and relays it, a tunnel per client address (`Upgrade: devstack-udp`
on the lane daemon's `/v1/tunnel/{port}`), each datagram a frame of its
length (two bytes, big-endian) and its bytes. A session ends after 60 s
without a datagram either way; nothing is held while a container starts.
The lane daemon sends a session's datagrams from a socket of its own to
the container on the lane's network.

- `udprelay`: framing, the requester's session table (limits, retry after
  a tunnel that did not open), the lane daemon's session.
- The requester asks for UDP when it starts the lane (`relay_udp`); a node
  that relays tells the lane daemon (`udp` in its file) and answers with
  `infra_udp_ports`. An older requester or node leaves the ports
  `not_forwarded`; the lane then says why (`not_forwarded_reason` in
  `GET /v1/lanes`, `devstack lane list`, the dashboard's lane header).
- A lane carried over a restart (ADR-0052) keeps its UDP ports.
- Docs: pool.md, dashboard-api.md, the devstack skill.
- Tests: framing, session table, idle timeout, a refused tunnel; an end to
  end test through a real lane daemon's tunnel to an echo socket, without
  Docker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
macOS refuses to send a UDP datagram larger than the socket's send
buffer, 9 KiB by default (`net.inet.udp.maxdgram`): the relay's 60 KB
test datagram failed with EMSGSIZE on the macos-14 runner. Both relays
raise a socket's send and receive buffers to hold any datagram a frame
carries, never lowering them; ADR-0056 point 5 says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit 20c7e83 into main Oct 23, 2026
13 checks passed
@7schmiede
7schmiede deleted the feat/udp-relay branch October 23, 2026 11:32
@7schmiede 7schmiede mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UDP ports of a lane on a node: forward them (a UDP relay through the node tunnel)

1 participant